UI Builder Client Script to Data Broker Script

Teo Gamarra
Tera Expert

Hello all! Is there any method to call a DataBrokerScript. Running this script from UIBuilder Client Script after capturing desired data.

function handler({api, event, helpers, imports}) {   
    var itemSelected = event.payload.value;
    // Trying to call the Data Broker script and pass the itemSelected as a parameter over here:
    api.someMethodToCallDataBrokerScript('DataBrokerScriptName', { itemSelected: itemSelected });
}

Or should create a GlideAjax instance, targeting the server-side script.
1 ACCEPTED SOLUTION

Hasan6
ServiceNow Employee
ServiceNow Employee

Hi Eberteo,

With the current screenshots, I am struggling to debug the issue.

Sure, let's get on a call to discuss this.

Do reach out to me at hasan.bilgrami@servicenow.com, and lets set something up.

Best

Hasan

View solution in original post

6 REPLIES 6

Hasan6
ServiceNow Employee
ServiceNow Employee

Hi eberteo,

There are 2 functions for you to use:

api - api.data.<data_resource_id>.execute(Object inputValues) if mutates data server is checked

api - api.data.<data_resource_id>.refresh() if mutates data server is unchecked

Note: You'll need to add the data broker to the data resources list of the experience

https://docs.servicenow.com/bundle/vancouver-api-reference/page/app-store/dev_portal/API_reference/a...

 

Best

Hasan

Hasam! I appreciate those insights they have been really helpful; after reading and debugging my Client Script ended up as follows:
function handler({api, event, helpers, imports}) {
   var dataSelected = event.payload.value[0];
   console.log("Item Selected is:", dataSelected);
   api.data.programprofiles_2.execute({
      name: dataSelected
    });
}
Item Selected is: 432696
Therefore having the number selected, I went to my Data Broker and start debugging to visualize if I was receiving the input value from there. I noticed the debugger is indeed being executed every time is triggered which makes me think api.data.programprofiles_2.execute does work however as in the picture attached I'm not able to visualize the dataSelected being received in the input. Currently my Data Broker has no Properties set and the Mutates server data is checked.
 
image.png

Hasam! I appreciate those insights they have been really helpful; after reading and debugging my Client Script ended up as follows:
function handler({api, event, helpers, imports}) {
   var dataSelected = event.payload.value[0];
   console.log("Item Selected is:", dataSelected);
   api.data.programprofiles_2.execute({
      name: dataSelected
    });
}
Item Selected is: 432696
Therefore having the number selected, I went to my Data Broker and start debugging to visualize if I was receiving the input value from there. I noticed the debugger is indeed being executed every time is triggered which makes me think api.data.programprofiles_2.execute does work however as in the picture attached I'm not able to visualize the dataSelected being received in the input. Currently my Data Broker has no Properties set and the Mutates server data is checked.
 
image.png

Hasan6
ServiceNow Employee
ServiceNow Employee

Hi Eberteo,

I think I've got the issue, you need to enter properties to read the name field in the data broker.

Add a property object in the properties field like:

[
    {
        "name":"name",
        "label":"Name",
        "description":"Enter he item name",
        "readOnly":"false",
        "fieldType":"integer",
        "mandatory":true,
        "defaultValue":""
    }
]

You will then be able to access the selected item using input.name

 

Hope this helps! If not, do revert, if possible with the data broker's screenshot, so that we can examine that and resolve this issue.

Best

Hasan