Get the sys_id of The Catalog Item from its related Catalog Task

Community Alums
Not applicable

Hi,

 

I am trying to Write an OnLoad  Client script on the Task table,

I want to get the Catalog Item sys_id when its Related Task form  is Loaded Is it possible?

 

Thanks

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Here is the solution

1. Create a Display business rule against sc_task Table with the script as

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    g_scratchpad.catItemSysId = current.request_item.cat_item;

})(current, previous);

2 Now create a OnLoad Client script

function onLoad() {
   //Type appropriate comment here, and begin script below
   alert(g_scratchpad.catItemSysId); //This will give catalog item SysId
} 

 

 

- Pradeep Sharma

View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Gowtham,

 

You can get the catalog item sys_id via CS + GlideAjax approach or the other approach is to do via Display BR + CS. Solution shared below.

Reference:

https://docs.servicenow.com/bundle/paris-application-development/page/script/business-rules/concept/... 

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Here is the solution

1. Create a Display business rule against sc_task Table with the script as

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    g_scratchpad.catItemSysId = current.request_item.cat_item;

})(current, previous);

2 Now create a OnLoad Client script

function onLoad() {
   //Type appropriate comment here, and begin script below
   alert(g_scratchpad.catItemSysId); //This will give catalog item SysId
} 

 

 

- Pradeep Sharma

Community Alums
Not applicable

Thank you Pradeep

You are very welcome Gowtham.