How to populate value in a field on approval table from workflow?

thirumala2
Tera Guru

Hi ,

We have a requirement of populating value from workflow to a given field on approval table for managed docs .

find_real_file.png

From the below workflow run script :

find_real_file.png

@shloke04 can u help ?

 

1 ACCEPTED SOLUTION

By mistake I have put a quotes while setting the value. You need to remove that:

Modified script below:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.query();
while(gr.next()){
gr.FIELDNAME = current.number.toString(); // Replace "FIELDNAME " with the one where you want to set on Approver table
gr.update();
}

Try now should work.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

36 REPLIES 36

Hi @thirumala 

Script will definitely work. Please use the updated script for fetching Document number below:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.query();
while(gr.next()){
gr.FIELDNAME = 'current.number.toString()'; // Replace "FIELDNAME " with the one where you want to set on Approver table
gr.update();
}

Just replace the field name where you want to copy on Approver Table and you should be good.

If this does not work then share your script and where you have added in your workflow.

I have tested in my PDI and works great for me.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

find_real_file.png

Hi @shloke04 ,

I tried this script in run script part of wf but its not working where as the Field on Approval table is Managed document which is a reference field referencing to dms_document table.

okay not an issue. i didn't knew that the field is a Reference type.

Couple of things to note here which is important to understand how Servicenow platform works and it will clear out your query as well:

1) When you are generating an Approval record for your Managed document record, there is already a field on Approval Table named as "Approving" which already stores Managed Document record id.

find_real_file.png

2) Secondly if you have created a Reference type field on Approval table and you are trying to store the Number of Managed document then that will never work as Reference field is supposed to store sys id of the target table which is Managed Document in your case and will show up a reference record ID.

If you want this field to just have number then, modify the dictionary of your new field on Approval table from Reference to string and then use the script which was shared above. Sharing it below as well for reference:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.query();
while(gr.next()){
gr.FIELDNAME = 'current.number.toString()'; // Replace "FIELDNAME " with the one where you want to set on Approver table
gr.update();
}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

find_real_file.png

find_real_file.png

Hi @shloke04 ,

I have added the above script and changed the field to string still its not populating .

 

By mistake I have put a quotes while setting the value. You need to remove that:

Modified script below:

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('document_id',current.sys_id);
gr.query();
while(gr.next()){
gr.FIELDNAME = current.number.toString(); // Replace "FIELDNAME " with the one where you want to set on Approver table
gr.update();
}

Try now should work.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke