Copy Request short_description to Requested Item short_description via workflow script

Cat
Mega Guru

 

Hi All,

 

I've created a script that is run via the workflow to set the Request short_description to what has been entered in the summary variable.

I'd like to now copy what is in the Request short_description to the Requested Item short_description (done this way so I don't have to customise both scripts for different catalog items.

This is what I currently have which works to update the request - how can I change it to work to update the request item from what is on the request?

 

var desc = current.cat_item.name;
var num = current.number;
var gr = new GlideRecord('sc_request');
if (gr.get(current.request)){
    gr.short_description = current.variables.summary;
    gr.requested_for = current.variables.request_for;
    current.requested_for = current.variables.request_for;
    gr.update();
   
}
 
Thanks in advance
2 REPLIES 2

Maddysunil
Kilo Sage

@Cat 

To update the short description of the requested item based on the short description of the request, you can use a similar approach as you did for updating the request:

 

 // Get the short description and number of the request
    var requestShortDescription = current.short_description;
    var requestNumber = current.number;

    // Query the requested item related to the request
    var requestedItemGR = new GlideRecord('sc_req_item');
    requestedItemGR.addQuery('request', current.sys_id); // Assuming 'request' is the reference field to the request table
    requestedItemGR.query();

    // Update the short description of each related requested item
    while (requestedItemGR.next()) {
        requestedItemGR.short_description = requestShortDescription;
        requestedItemGR.update();

        gs.info('Updated short description for requested item: ' + requestedItemGR.number);
    }

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

Thank you, but unfortunately, this is not working. I'd be happy to use the variable instead of copying it from the Request. Would that be easier?

 

So I would instead do:

 

var desc = current.cat_item.name;
var num = current.number;
var gr = new GlideRecord('sc_req_item');
if (gr.get(current.requesteditem)){
    gr.short_description = current.variables.summary;
 
    gr.update();
   
}