How to retrieve data with a Script Include in UI Builder?

gjz
Mega Sage

I'm really new to UI Builder and have a business requirement that I need help with.

 

Currently, in the core UI forms for catalog tasks (SCTASK), we have a UI Macro on the form that provides a list of consolidated work notes and user comments for the entire request so none get missed when fulfilling a request.  The UI macro calls a script include that gathers the data based on two parameters passed - the SCTASK sysid and the RITM sysid.

 

I need the same functionality for Service Operations Workspace and I'm stuck on how to create a data resource to call the script include.  I assume I can pass parameters to the data resource with a client state parameter or field value from the form controller, I just don't know how to do that in a data resource, or even what kind of data resource since I want to re-use the script include code.

 

Can someone help me out, please?

1 ACCEPTED SOLUTION

gjz
Mega Sage

It turns out you can call a Script Include from UI Builder, and it was easy and did not require a catalog client script or REST API.  It may not be efficient, but it works.

 

Here is how I did it:

Business requirement: Display a consolidate list of work notes and comments for a catalog task in the side bar of a standard record page that is open on a catalog task.  

 

1. On the standard record page of the workspace I'm using, I created a new Transform data resource.

2. In the data resource, I wrote the script I needed to get the data.  Once I had this working and it returned data, I 

3. Copied the script into a new function in an existing Script Include that is client callable.

4. Changed the Transform to call the script include the same way you normally would.  For those who are visual, this is what it looked like:

Transform Script Include.png

 

data resource.png

 

I still have to hook it up to the sidebar, add events to refresh data, limit it to only being used for a catalog task record, etc., but I have data!

View solution in original post

11 REPLIES 11

Zod
Giga Guru

Thx to all. Not working with Builder so far due to limitations (like most of the new stuff… mostly the f*cking FLOW BS — loved my workflow 😄), but ok — can’t turn back time 😉

 

I was NOT aware of the workspace part after the script field in the UI Action for Workspace…!!

That is doing the trick.

 

So ... UI Action as usual with client and server-side coding via…

 

// client side checks before ...

...

 

//serverside

if (typeof window == 'undefined') {
current.status = 3; 
current.update();
action.setRedirectURL(current);
}

... and workspace part adding the same ... and at the end the action is called witch is only set in the upper script filed.

 

function onClick() {
var test = g_form.getValue('test');
    g_form.clearMessages();

    if (!test) {
        g_form.addErrorMessage(getMessage('test_msg'));
        return false;
    }

    g_form.setValue('approval', 'rejected');
    g_form.submit('my_action_name');   // Action name

}

 

 

Works now. 

 

gjz
Mega Sage

It turns out you can call a Script Include from UI Builder, and it was easy and did not require a catalog client script or REST API.  It may not be efficient, but it works.

 

Here is how I did it:

Business requirement: Display a consolidate list of work notes and comments for a catalog task in the side bar of a standard record page that is open on a catalog task.  

 

1. On the standard record page of the workspace I'm using, I created a new Transform data resource.

2. In the data resource, I wrote the script I needed to get the data.  Once I had this working and it returned data, I 

3. Copied the script into a new function in an existing Script Include that is client callable.

4. Changed the Transform to call the script include the same way you normally would.  For those who are visual, this is what it looked like:

Transform Script Include.png

 

data resource.png

 

I still have to hook it up to the sidebar, add events to refresh data, limit it to only being used for a catalog task record, etc., but I have data!