Set up our sample integration with the basic data your users need to perform print REST API calls by pressing the NiceLabel Print button in D365SCM.

In D365SCM, go to System administration > Setup > NiceLabel Printing Integration

image8.tmp

Opening NiceLabel Printing Integration setup in D365SCM.

Configure the following 3 setup tabs:

  • General

  • Printers

  • Templates

Before you begin, carefully configure any data you use to perform print REST API calls.

General tab

image9.tmp

The General setup tab includes your account information necessary for every REST API call.

Code: General tab

The NLPIntegrationParameters form saves your parameters into the NLPGeneralParameters table.

Printers tab

image10.tmp

Configuring the Printers setup tab for D365SCM users.

The Printers setup tab allows your users to retrieve a list of printers connected to NiceLabel Cloud and makes them available to select on the printing form.

On the Printers tab, click Refresh so you can:

  • Get an updated list of printers connected to NiceLabel Cloud.

  • Save your list of printers to your D365SCM database.

If you configure your General tab correctly, you get a successful response:

image11.tmp

If you configure your General tab incorrectly, you get an error:

image12.tmp

Code: NLPIntegrationParameters

Clicking Printers > Refresh calls the NLPIntegrationParameters.RefreshButton_OnClicked method. This method has 3 main functions:

  • Deleting existing printer lists from the NLPPrinterParameters table.

  • Getting new printer lists from REST APIs.

  • Saving new printers list into the NLPPrinterParameters table.

Note the NLPrinting class in this method. To get lists of connected printers, call its associated NLGetPrinters method.

public static void RefreshButton_OnClicked(FormControl sender, FormControlEventArgs e)
{
        // delete previous printers list
        
        ...

        NLPrinting NLPrint = new NLPrinting();
        System.String[] listOfPrinters = NLPrint.NLGetPrinters();
        int numOfPrinters = listOfPrinters.Length;

        ...
        
        // save new printers list
}

Code: NLPrinting class basics

NLPrinting is a C# wrapper for NLApiClient.dll. Customize your integration by changing the value of the useCloudPrinting parameter to print on cloud printers with Cloud Print API or classic printers connected to NiceLabel Automation with predefined Cloud Trigger API configurations (.misx).

  • To use Cloud printers, set useCloudPrinting to true.

  • To use Classic printers, set useCloudPrinting to false.

class NLPrinting
{
    private boolean useCloudPrinting = true;

    public boolean configValid;
    private str NLPrintServiceURL;
    private str NLPrintSubscriptionKey;
    private NLApiClient.BaseIntegrator obj;
    ...
}

The NLPrinting class constructor reads your Service URL and Subscription Key from the NLPGeneralParameters table and makes sure they are present. You save both of these required parameters in the Integration Setup > General tab. The check validates your instance of cloud integrator class based on the useCloudPrinting parameter. Your class instance is responsible for all REST API calls.

class NLPrinting
{
   ...
    void new()
    {
        this.NLPrintGetURLAndKey();

        if(configValid)
        {
            if (useCloudPrinting)
            {
                obj = new NLApiClient.CloudPrintIntegrator(NLPrintServiceURL);
            }
            else
            {
                obj = new NLApiClient.CloudTriggerIntegrator(NLPrintServiceURL);
            }
        }
        else
        {
            obj = null;
        }
    } 
    ...
}

Code: NLPrinting.NLGetPrinters

You call the REST API based on your UseCloudPrinting configuration:

public System.String[] NLGetPrinters()
{
    if (configValid)
    {
        if (useCloudPrinting)
        {
            return (obj as NLApiClient.CloudPrintIntegrator).GetPrintersArray(NLPrintSubscriptionKey);
        }
        else
        {
            return (obj as NLApiClient.CloudTriggerIntegrator).GetPrintersArray(NLPrintSubscriptionKey);
        }
    }
    else
    {
        return null;
    }
}

Templates tab

Printing from D365SCM with REST APIs uses label templates stored in NiceLabel Cloud > Documents. To make selecting templates easier for your users, you create a list of label templates and assign each template a user-friendly name in the Templates setup tab.

image13.tmp

Adding and naming label templates from Control Center to use in D365SCM.

Add label template paths from your files stored in Control Center > Documents.

  1. Right-click a label template file you want to include and choose Get info. The File info window opens:

    image14.tmp
  2. Copy the file path after your NiceLabel Cloud URL:

    image15.tmp
  3. Paste the path in the Template Path field for a new template in the D365SCM > NiceLabel Printing Integration Setup > Templates tab.

    image16.tmp
  4. Type a unique user-friendly Template Name for each template you add so your users know which labels to select and print from D365SCM.

Code: templates tab

The NLPIntegrationParameters form saves your template paths to the NLPTemplateParameters table.