- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 06:07 AM
Hi All,
I am working on the reclamation workflow . I have to pass four input variables and triggered the workflow from script include. The four input variables are 1. Domain Controller, User Name, AD GroupName and Shared Domain .
I am able to get all the input using Glide Query from different table . My only issue is how to send all the inputs to workflow inputs (Remove AD Group). Please find the script include which I have written for the above mentioned logic.
Script Include:
var RemoveAD = Class.create();
RemoveAD.prototype = {
initialize: function() {},
type: 'RemoveAD'
};
RemoveAD.revokeAD = function(softwareGr) {
var UserAdDomain;
var ADDomain;
var ADUserName;
var domainController = 'wmservice.corpnet1.com';
var gr_install = new GlideRecord("cmdb_sam_sw_install");
gr_install.addQuery('sys_id', softwareGr);
gr_install.query();
//gr_install.get('03f31264dbc658942973d844ca96198b');
if (gr_install.next()) {
var discoModel = gr_install.getValue('discovery_model');
//gs.print('Discovery Model:' +discoModel );
var softwaremodelids = SAMPremiumUtils.getSoftwareModelsFromDiscModel(discoModel);
//gs.print('SW Model IDs:' + softwaremodelids);
var gr = new GlideRecord('sn_client_sf_dist_application');
gr.addEncodedQuery('modelIN' + softwaremodelids);
gr.query();
if (gr.next()) {
// AD Domain, User AD Domain , AD UserName & Domain Controller(Pending )
ADDomain = gr.getValue('display_name');
UserAdDomain = gr_install.installed_on.assigned_to.u_ad_domain;
ADUserName = gr_install.installed_on.assigned_to.user_name;
gs.print(ADDomain);
}
// Condition to be applied for Domain Controller
}
//calling the workflow GSK AD - Remove User from Group
// Have to get the workflow input to pass & triggered the workflow
// Not sure about the syntax how to pass the input:ADDomain, UserAdDomain, ADUserName and domainController
var wfVars = {};
wfVars.
RemoveAD.startWorkflow("GSK AD - Remove User from Group", softwareGr, "", wfVars);
};
RemoveAD.startWorkflow = function(wfName, record, operation, wfVars) {
var wf = new global.Workflow();
var workflowId = wf.getWorkflowFromName(wfName);
if (gs.nil(workflowId)) {
gs.info('workflow: ' + wfName + ' not found');
return;
}
var contextId = wf.startFlow(workflowId, record, operation, wfVars);
return contextId;
};
Please help me in this regard.
Regards,
Aquib
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 08:37 PM
Try to run once and verify
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 06:21 AM
Hi,
I have shared solution for how to pass inputs to workflow and how to get them in workflow
check this link where I shared the answer
Trouble Accessing variables from inbound action
sharing the script here again
1) Create workflow input variable
2) Then send the data like this
var inc = new GlideRecord('incident');
inc.get('8d44ecd62ff56010aedd55f62799b691');
inc.short_description = 'test';
inc.update();
var wflow = new Workflow();
var wfId = wflow.getWorkflowFromName("Incident") ;
var vars= {};
// you need to set the value in the same column name u_username
vars.u_username = 'my_id_to_workflow';
wflow.startFlow (wfId, inc, inc.operation() , vars) ;
3) Then access it like this
// u_username is the column name which you need to use to access the value
gs.info("workflow value"+ workflow.inputs.u_username);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 08:00 AM
Hi Ankur,
Thank you for the much needed help. Appreciate your effort . I have updated my scripts.
Please review the scripts . I reviewed the link which you have shared and tried to replicate the same .
Please let me know if any modification is required.
if (gr_install.next()) {
var discoModel = gr_install.getValue('discovery_model');
var softwaremodelids = SAMPremiumUtils.getSoftwareModelsFromDiscModel(discoModel);
var gr = new GlideRecord('sn_client_sf_dist_application');
gr.addEncodedQuery('modelIN' + softwaremodelids);
gr.query();
if (gr.next()) {
// AD Domain, User AD Domain , AD UserName & Domain Controller(Pending )
ADDomain = gr.getValue('display_name');
UserAdDomain = gr_install.installed_on.assigned_to.u_ad_domain;
ADUserName = gr_install.installed_on.assigned_to.user_name;
gs.print(ADDomain);
}
// Condition to be applied for Domain Controller
}
//calling the workflow GSK AD - Remove User from Group
// Have to get the workflow input to pass & triggered the workflow
// Part which is modified
var wfVars = {};
wfVars.u_domaincontroller=domainController;
wfVars.u_remove_user=ADUserName;
wfVars.u_groupname = UserAdDomain;
wfVars.u_share_domain=domainController;
RemoveAD.startWorkflow("GSK AD - Remove User from Group", softwareGr, "", wfVars);
};
RemoveAD.startWorkflow = function(wfName, record, operation, wfVars) {
var wf = new global.Workflow();
var workflowId = wf.getWorkflowFromName(wfName);
if (gs.nil(workflowId)) {
gs.info('workflow: ' + wfName + ' not found');
return;
}
var contextId = wf.startFlow(workflowId, record, operation, wfVars);
return contextId;
};
Also I will add run script activity to verify the inputs in the workflow's AD - Remove User from Group
Regards,
Aquib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2022 08:37 PM
Try to run once and verify
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2022 02:43 AM
The Issue has been resolved . Issue with line:var removeADInclude = new global.RemoveAD.revokeAD(gr_install);
when updated to global.RemoveAD.revokeAD(gr_install); it worked . The workflow is getting triggered.