Variables not available on case forms

Hafsa1
Mega Sage

I have 2 similar RecordProducer via which we are creating CSM case.

I want to write same BR on case table for both record producer but it is giving error.

like one similar variable in both RP 

var costcenter = current.variables.cost_center (belong to first RP)

var costcenteruat =current.variables.cose_center_uat (belong to second RP)

 

when I tested using log, if i'm raising using first RP then, value coming in second variable as "undefined" and BR stops.

if i'm raising using second RP then, value coming in first variable as "undefined" and BR stops.

 

Is there any way that I can use variables from both RP and if any variables has value then BR should execute.

 

1 ACCEPTED SOLUTION

Hi @Hafsa1 ,

 

Try below code.

gs.info("begin");

// Check if cost_center exists and get its value
var costcenter = current.variables.cost_center ? current.variables.cost_center.getDisplayValue() : '';
gs.info("middle: " + costcenter);

// Check if cost_center_uat exists and get its value
var costcenteruat = current.variables.cost_center_uat ? current.variables.cost_center_uat.getDisplayValue() : '';
gs.info("end: " + costcenteruat);

// Perform further logic only if at least one variable has a value
if (costcenter || costcenteruat) {
    // Your additional business rule logic goes here
    gs.info("Proceeding with Business Rule logic...");
} else {
    gs.info("No valid cost center variable found. Business Rule will not proceed.");
}

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Hafsa1 

try this in your BR script

var costcenter = current.variables.cost_center; // (belong to first RP)
if (costcenter) {
    // logic for 1st RP
}

var costcenteruat = current.variables.cose_center_uat; // (belong to second RP)
if (costcenteruat) {
    // logic for 2nd RP
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hafsa1
Mega Sage

while initializing in variables it is giving undefined and not moving further.

 

gs.info("begin");
var costcenter = current.variables.cost_center.getDisplayValue();
gs.info("middle"+costcenter);
  var costcenteruat= current.variables.cost_center_uat.getDisplayValue();
gs.info("end"+costcenteruat);
 
when I'm using RP1 (cost_center) , it stops at gs.info("middle");
 
when I'm using RP2 (cost_center_uat) , it stops at gs.info("begin");
Seems it is not able to find the variable itself

@Hafsa1 

Did you try the code I shared? It should work and check if value is there and not undefined then run your logic
please share your updated code

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Hafsa1 

I believe I also provided the correct answer to your question.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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