To populate the requestor of catalog item from IMS record in Agent Workspace

rishabh31
Mega Sage

Dear Team,

I am following the below-solved URL to achieve that same requirement and tried the steps and script as provided in this:

https://www.servicenow.com/community/csm-forum/passing-variables-from-interaction-record-ti-catalog-...

In my case, I need to populate 'requestor' instead of 'requested for' of catalog item. Accordingly, I modified the onload catalog client script (screenshot and script below) as provided in the above URL-

rishabh31_0-1682582860777.png

Script:

 

 

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var reqContact = localStorage.getItem("lastname");
    if (reqContact)
        g_form.setValue('requestor', reqContact);
    localStorage.clear();
}

 

 

 

After saving and testing, found it does not work as expected. Expectation is when user clicks on button 'Create Request' on Agent Workspace IMS record, it redirected user to a Service Catalog contains all Catalog items, then user selects any Catalog item per their requirement to create a request under that respective IMS record and when that catalog item form opens then its variable 'requestor' (part of a variable set in several catalog items and is of reference type Variable with Default Value set as 'javascript:gs.getUserID()' i.e., Currently logged in user) should reflect the same name as of 'opened_for' of its respective Interaction Record in Agent Workspace. But this is not working as expected as shown in below screenshots.

My testing Result:

rishabh31_2-1682583340260.png

Here Interaction record Opened for is 'David Miller'

when clicked on 'Create Incident', the 'service catalog' page opens on Agent workspace (shown in below screenshot)

rishabh31_3-1682583509399.png

Then here clicked on a catalog item- 'Access Change Request', it opens form but 'Requestor' of the form is Currently logged in user NOT David Miller (screenshot below)

rishabh31_4-1682583738912.png

This is intended to be the same as Opened for of Interaction record per Onload catalog client script written (screenshot and script provided above) because this request is opening through the 'Create Request' button on the Interaction record in the Agent workspace.

 

Please help me get this accomplished with a correct script to implement and steps.

 

Thanks in advance

 

1 ACCEPTED SOLUTION

In the 1st script you only need to set the value.

You are setting it but also clearing it outright.

Of course because of the clearing, the other script will find no value.

 

You could also use sessionStorage in place of localStorage.

 

Thus the 1st script (Interaction onChange of opened_for) would be:

 

function onChange (control, oldValue, newValue, isLoading, isTemplate) {
	sessionStorage.setItem('openedFor', g_form.getValue('opened_for'));
}

 

The 2nd script onLoad Catalog Client Script would be:

 

function onLoad () {
	var openedFor = sessionStorage.getItem('openedFor');

	if (openedFor)
		g_form.setValue('requestor', openedFor);

	sessionStorage.removeItem('openedFor');
}

 

View solution in original post

19 REPLIES 19

-O-
Kilo Patron
Kilo Patron

Can you share the other part of the solution, the Interaction onChange of Opened for?

Hi thank you for your response, I am not aware about this other part as I am new to such asks please help me to create this other part and requesting your assistance to allign me with steps to follow to get this acheived.

 

Please help

localStorage here acts like a super global g_scratchpad.

Just like when using g_scratchpad, you need to do two things:

- add the data to it in a display Business Rule

- consume that data in Client Scripts.

With local storage it is the same, you need to do two things:

- add the data to it in a Client Script on Interaction - this would be the missing piece I am talking about and which @Weird is talking about.

- consume the data in a Catalog Client Script.

 

Just remember that this is super global, so if you have two Create Requests open, there might be trouble.

A complete solution would store the data separately per Create Request tab.

Also, even in the post you referenced, the very last entry talks about creating an onChange Client Script too on Interaction.