Save data from Catalog Client Script into Session client data

Zhivko
Kilo Expert

Hi guys,

I am trying to record the data that a user enters in Catalogue Item variables (short_description and description) and put that into the request (as well as the requested item).  I can get it into the item - that works, but getting it into the request appears to be trickier. I was thinking the data could be stored in the session, but it says "The object "gs" should not be used in client scripts."

It looks like the Request is created after the Request item, so I need a way to store the information that the user fills in and then write it in the request with a business rule. Alternatively, I could get the same info from the requested item, but I do not know how I can address the item from the request table.

Any help here is very welcome
Thanks 🙂
Zhivko


(please explain things as if you are talking to an idiot - my skills here are quite basic)

1 ACCEPTED SOLUTION

I didn't go too deep into testing it in my DEV instance, but it definitely copied over the Short Description on an item that I submitted.  As for how often it runs, just make sure that you have the condition set to look for the Request field to change and no longer be empty.  That scenario should only ever be reached once.

You could also do this from the REQ side of the house if you only want to do it on insert.  

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

var ritm = new GlideRecord('sc_req_item');
if (ritm.get('request',current.getValue('sys_id') {
current.short_description = ritm.short_description;
current.description = ritm.descritpion;
}

})(current, previous);

 

I put in both Before and After business rules on the REQ and RITM tables to log some statements validating that the data would be there.  Based on the order of the statements and the lack of "Request Number" in the RITM business rules, I would have to assume that the RITMs are created first, and then the REQ is created and linked to the RITMs.

find_real_file.png

View solution in original post

8 REPLIES 8

Alikutty A
Tera Sage

Hi,

The request is created initially and then the requested items. You can write an after insert business rule on the sc_req_item table and write a script to populate the required data on the request. 

Sample script that can be used.

var request = new GlideRecord('sc_request');
request.addEncodedQuery('sys_id', current.request); //get your request
request.query();
if(request.next()){
 //Make sure the variable names are correct
 request.short_description = current.variables.short_description; //copy the variables from RITM
 request.description = current.variables.description;
 request.update();
}

 

Would that work though - I mean the request does not yet exist when this is running on the insert of the req item?

In any case, I will give it a try tomorrow - thanks for the suggestion.

It should ideally, If you are creating RITM from a catalog item UI, then the request is created first and then the RITM.

Hi,

The request gets created first followed by request item. So it should be available.

Mark the comment as helpful if it helps.