Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

client script code:

var ga = new GlideAjax('checkci');

      ga.addParam('sysparm_name', 'getCI');

      ga.addParam('sysparm_ci', g_form.getValue("field name"));

      ga.getXMLWait(updateCI);

}

     

function updateCI(response) {

      var answer = response.responseXML.documentElement.getAttribute("answer");

      if (answer == 'true') {

              g_form.alert('your error message');

              return false;

      }

 

Script include:

 

var checkci = Class.create();

checkci.prototype = Object.extendsObject(AbstractAjaxProcessor, {

      getCI: function () {

              var ci = this.getParameter('sysparm_ci');

              var loc = new GlideRecord('your table name');

               loc.addQuery('name',ci);

               loc.query();
               if (loc.next()){

return 'true';

}

}

});

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Hello @Nayan Dhamane 

Thanks for the script!

I have tried below but no luck, can you pls check?

 

Script include.

var checkci = Class.create();

checkci.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCI: function() {
var ciName = this.getParameter('sysparm_ci');
var ciGR = new GlideRecord('cmdb_ci_service_discovered'); // Replace with your actual CI table name
ciGR.addQuery('name', ciName);
ciGR.query();

if (ciGR.next()) {
return 'true';
}
return 'false';
},
type: 'checkci'
});

 

Onsubmit catalog client script.

function onSubmit() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('checkci');
ga.addParam('sysparm_name', 'getCI');
ga.addParam('sysparm_ci', g_form.getValue("name"));
ga.getXMLWait(updateCI);

function updateCI(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
g_form.alert('Already Exists');
return false;
}
}
}

Hello @akin9 ,

Mostly looks good to me just would suggest to add else statemtent to return false.

Please add logs in the script include to debugg it and check where you are facing an issue.

 

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Nayan  Dhamane
Kilo Sage

Hello @akin9 ,

Unfortunately workflows and flows are triggered from record producers once a record is actually created.  So the application service would need to be created first, the workflow/flow would detect that and launch the approval and go from there.  If you want a step in between the creation of the record the service catalog would be the best method to accomplish this where you could have a flow run that initiate the approval and once approved create the business service with the data from the request.

 

This above response is provided by a ServiceNow employee - link

 

Please use a catalog item for approval instead of record producer.

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.