Workflow set value option not working properly

pluurenvanj
Giga Contributor

We have defined a workflow on the sc_req_item table. I want to populate the short description on the parent request from this workflow.

I see the option to do this.... I can select the "parent.short_description" field and can give this a specific content, but it does not work as desired.

I was looking for what exactly happens chonologically. First the workflow "Service Catalog Request" is executed. In this flow the short description on the request is populated with value "X". When this workflow finishes the next workflow (on requested item level) is executed. My assumption was that a "set values" step in this flow on the short description field of the RITM's parent (being the REQ) would overrule the previously populated value. This is not the case.

Purpose of a specific short description is that I would like to make an acception on the notification that is sent from this type of request.

Anyone any ideas how to do this ?

Regards,

Jeroen

1 ACCEPTED SOLUTION

Ravi Prasad1
Tera Guru

Hi Try below code



var gr = new GlideRecord('sc_request');


gr.addQuery('sys_id',current.request);


gr.query();


gr.next();


gr.short_description = 'Requests_new_short_description';


gr.update();



View solution in original post

6 REPLIES 6

williamsun
Mega Guru

The general rule is that to modify a record you need an object variable (Glide Record) to be on that record.


When you are working in a context, like you are on the sc_req_item context because the workflow is attached to it, you can use the "current" object and it will always be pointing to the object on that table.


So what is happening here is that you are trying to modify the parent record, while you are in the context of the sc_req_item record.


How to solve it?


You need to create a script where you will make a GlideRecord variable on the parent table, point it to the appropriate record, modify the field, and then update the record.



Try this script within what you are doing:



var parent = new GlideRecord('sc_request');


parent.addQuery('sys_id',current.parent.sys_id);


parent.query();


parent.next();


parent.short_description = 'Requests_new_short_description';


parent.update();



Also note that since you are not on the sc_request record, you need to do an update() command, otherwise the record will not be updated.


Dear William,



Thanks for your answer. It does work, but now a new complementary Request is generated with nothing in it.



Regards,


Jeroen


Hmm, maybe use a different variable name that is not "parent", that might be causing some static:



var gr = new GlideRecord('sc_request');  


gr.addQuery('sys_id',current.parent.sys_id);  


gr.query();  


gr.next();  


gr.short_description = 'Requests_new_short_description';  


gr.update();  


William,



Regret to tell you, that the result is the same.



Regards,


Jeroen