Record producer approval

akin9
Tera Contributor

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!

 

33 REPLIES 33

@akin9 

try this

// 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.source_table = recordProducerGR.task.sys_class_name;
approval.document_id = 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);
}

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar ,

Sry ,Still no luck 

Record is created after submitting the req.

I have added two users on the approval activity in the workflow.FYI

 

akin9_0-1690801416557.png

akin9_1-1690801536029.png

 

 

@akin9 

did you add some logs and debug?

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar ,

No i have not done.

@akin9 

please do this and share the analysis

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader