- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 04:56 AM
Hi ,
We have a requirement of populating value from workflow to a given field on approval table for managed docs .
From the below workflow run script :
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2022 05:49 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 09:32 AM
Hi
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2022 03:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2022 03:57 AM
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.
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2022 05:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2022 05:49 AM
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
Regards,
Shloke