Need to populate the data in the incident after submitting the record producer

Supriya KM
Tera Contributor

Hello Everyone,

I have a record producer(incident table), after submitting the form incident will get submitted. In the incident, I have a field as Service(reference - cmdb_ci_service_business) currently it is empty where I need to populate the data which is part of the cmdb table(eg: report). Can anyone explain how I can achieve this.

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

HI @Supriya KM ,
I trust you are doing great,
You can achive it via Business rule :

(function executeRule(current, previous /*null when async*/) {
    
    // Retrieve data from the CMDB table
    var cmdbRecord = new GlideRecord('cmdb_ci_service_business');
    cmdbRecord.addQuery('name', 'report'); // Assuming 'report' is the record you want
    cmdbRecord.query();

    if (cmdbRecord.next()) {
        // Set the Service field with the cmdb record
        current.u_service = cmdbRecord.sys_id; // Replace 'u_service' with the actual field name
    }

})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Supriya KM 

 

OOTB Record producer code here. But a Service has many values, are you planning to hard code one value?

 

 
current.contact_type = 'self-service';
// Add your code here
current.caller_id = caller;
var prodCommentStr = producer.comments + "";
if (prodCommentStr.length > 80)
    current.short_description = prodCommentStr.substring(0, 80);
else
    current.short_description = prodCommentStr;
current.description = prodCommentStr;

var incRPUtil = new LinkRecordProducerToIncident();
incRPUtil.linkRecordProducerToParentIncident(RP.getParameterValue('sysparm_parent_sys_id'), current);


*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Amit Gujarathi
Giga Sage
Giga Sage

HI @Supriya KM ,
I trust you are doing great,
You can achive it via Business rule :

(function executeRule(current, previous /*null when async*/) {
    
    // Retrieve data from the CMDB table
    var cmdbRecord = new GlideRecord('cmdb_ci_service_business');
    cmdbRecord.addQuery('name', 'report'); // Assuming 'report' is the record you want
    cmdbRecord.query();

    if (cmdbRecord.next()) {
        // Set the Service field with the cmdb record
        current.u_service = cmdbRecord.sys_id; // Replace 'u_service' with the actual field name
    }

})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hello @Amit Gujarathi 

Thank you hope you are doing great!!

Thanks for your prompt answer, it worked for me!!