- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on â01-03-2022 09:44 AM
In your day-to-day ServiceNow Administration or Development job, you may run into some cases where you'll need for either troubleshooting or testing purposes have test runs of Workflows.
It can be time consuming to do this by re-filling each catalog item from the start or you may just want to run a subflow of a workflow instead of the entire workflow.
This is possible via background scripts:
Example workflow with OOB Create AD Object in it
var w = new Workflow();
var context = w.startFlow(w.getWorkflowFromName('Subflow of AD Account Creation'),
'sc_req_item',
null,
{ u_userdata: '{\"c\":\"EE\",\"countryCode\":\"233\",\"co\":\"Estonia\",\"userPrincipalName\":\"Testaccount.AARETEST@AareCompany.com\",\"proxyaddresses\":\"SMTP:Testaccount.AARETEST@AareCompany.com\",\"givenName\":\"Testaccount\",\"company\":\"AareCompany\",\"sn\":\"AARETEST\",\"sAMAccountName\":\"AARETEST\",\"displayName\":\"AARETEST Testaccount\",\"title\":\"ServiceNow Specialist\"}',
u_ou: 'OU=Employees,OU=Users',
u_displayname:'AARETEST Testaccount',
u_samaccountname:'AARETEST'
});
In this example you'll have to note the following:
- This creates a workflow and adds a context, and onto that context the variables. (reference: https://developer.servicenow.com/print_page.do?release=quebec&category=null&identifier=c_WorkflowAPI&module=api)
- u_userdata seems pretty odd right? đ This is because in it every " is escaped with a \
Point 2 is very specific to the Workflow OOB Activity Create AD Object. In this activity definition, the script will clean the input context for ObjectData with specific criteria which means you'll have to escape every " with a \
Example without Create AD Object
var w = new Workflow();
var context = w.startFlow(w.getWorkflowFromName('Query AD Workflow'), null, null, {u_domainController: '192.168.1.123', u_username:'aare.pajuste'});
Conclusion
As you can see in the Query AD Workflow we don't have complex input thus it does not require the same escape characters. You'll have to note though that other workflows will have different results based on how input is handled on the activities within đ
- 1,900 Views
