current.variables record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 02:36 AM
I am building a record producer for requesting access to system and trying to set up approval in the associated workflow.
So if AustriaFireSec is true ad "Bob" to the list of approvers, AustriaProdTBSP add "Mary" etc.
However the approval just skips
The code:
// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.
//
// For example:
// answer = [];
// answer.push('id1');
// answer.push('id2');
answer = [];
if (current.variables.AustriaFireSec =='true'){
answer.push('f3bd6a9018c5740059b4f1a40b4e6ae2');
}
if (current.variables.AustriaProdTBSP =='true'){
answer.push('333912b60a0aa03201d3003fea2496f2');
}
if (current.variables.Sec_BE =='true'){
answer.push('37410d7c0a0aa03201dae6a5f40f2d70');
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 02:56 AM
Hi Kelly,
On which table you have created workflow as record producers will not have associated workflows?
if you want to create approvals and then corresponding tasks, then go with catalog items.
Thanks and regards,
Swamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 03:02 AM
The table is custom (u_request) and I have been able to use current.variables in the past for other purposes such as scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 03:11 AM
Hi Mark,
Yes, we can use current.variables.variabl_name in record producer script. if you want to create records from the producer script then you can write the script like below.
var gr = new GlideRecord('sysapproval_approver');
gr.initialize();
gr.document_id = current.sys_id;
gr.sys_approval = current.sys_id;
if(current.variables.AustriaFireSec =='true'){
gr.approver = 'f3bd6a9018c5740059b4f1a40b4e6ae2';
gr.insert();
}
else if(current.variables.AustriaProdTBSP =='true')
{
gr.approver = '333912b60a0aa03201d3003fea2496f2';
gr.insert();
}
else if(current.variables.Sec_BE =='true')
{
gr.approver = '37410d7c0a0aa03201dae6a5f40f2d70';
gr.insert();
}
Thanks and regards
Swamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2016 04:55 AM
Swamy,
When said script I meant within the workflow as an example I have a record producer to let group managers request access to a ServiceNow group.
There are two fields
user
group
I have a script in the workflow:
//Create a new group relationship record for this user
var rec1 = new GlideRecord('sys_user_grmember');
rec1.initialize();
rec1.user = current.variables.u_caller;
rec1.group = current.variables.group;
rec1.insert();
current.u_resolved_by = current.opened_by;
current.state = 4;
And this works fine, why can I not use current.variables in an approval!!!
Regards
Mark