Record producer approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 01:11 AM
Hello Experts,
We have created a record producer to create a new application service.
As of now If user submit a request new application service will create.
we have created a workflow but not working , dont know how to achieve it.
Table - "cmdb_ci_service_discovered"
Approval group - "SN_New_Management"
Requirment
1. we want to add Group approvals on that request after approval only new record needs to be created.
kindly support to achieve!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 01:16 AM
I assume your target table for record producer is -> cmdb_ci_service_discovered
You can add workflow to that table and use IF activity inside it to check if the record got submitted from record producer or not and if yes then only trigger the workflow and send approval or else you can end the workflow
To check this you can use the table "sc_item_produced_record"
Query this table with your record sysId i.e. current.sys_id and handle the logic
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 02:59 AM
Hi @Ankur Bawiskar @Nayan Dhamane
Thank you for the Quick replies.
I have added below script on if activity on the workflow.
but not working as expected, pls correct me and support.!
After submitting the request, it is creating a new record.
NOTE: No approval field on that form.
// Check if the current record was submitted from a record producer (catalog item)
var currentRecord = current;
var recordProducerGR = new GlideRecord('sc_item_produced_record');
recordProducerGR.addQuery('table', 'cmdb_ci_service_discovered');
recordProducerGR.addQuery('sc_produced_item', currentRecord.sys_id);
recordProducerGR.query();
// Check if there is a matching record producer for the current record
if (recordProducerGR.next()) {
// Example: Trigger an approval
var approval = new GlideRecord('sysapproval_approver');
approval.initialize();
approval.sysapproval = currentRecord.sys_id;
approval.approver = gs.getUserID(); // Assign the current user as the approver
approval.state = 'requested'; // Set the initial state to 'requested'
approval.insert();
// Log the message
gs.info('Approval requested for record: ' + currentRecord.number);
} else {
// Example: End the workflow
currentRecord.setAbortAction(true); // End the workflow
// Log the message
gs.info('Workflow ended for record: ' + currentRecord.number);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 03:27 AM
I have made some updates to script, please use that and see once
// Check if the current record was submitted from a record producer (catalog item)
var recordProducerGR = new GlideRecord('sc_item_produced_record');
recordProducerGR.addQuery('task', current.sys_id);
recordProducerGR.query();
// Check if there is a matching record producer for the current record
if (recordProducerGR.hasNext()) {
// Example: Trigger an approval
var approval = new GlideRecord('sysapproval_approver');
approval.initialize();
approval.sysapproval = current.sys_id;
approval.approver = gs.getUserID(); // Assign the current user as the approver
approval.state = 'requested'; // Set the initial state to 'requested'
approval.insert();
// Log the message
gs.info('Approval requested for record: ' + current.number);
} else {
// Example: End the workflow
// Log the message
gs.info('Workflow ended for record: ' + current.number);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-31-2023 03:40 AM
Hi @Ankur Bawiskar ,
Sry i have used the above but no luck.,
Actually, no approval field on the AS form, maybe it will be the issue?
Pls correct me.
