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

Tim Provin
Mega Guru

You should be able to do this in a Business Rule on the RITM without any code.

find_real_file.png

find_real_file.png

If this works, that would be great - my only concern is that on the insert of the req item, the request does not exist yet(or am I wrong?) and running it on every update might be a bit too much given that I want to capture it once - will give it a go tomorrow - thanks

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

This only really works the way I needed it to on the REQ table, so this was what does it for me. Thanks! 

(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.description;
}

})(current, previous);