- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-28-2025 04:16 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-28-2025 04:58 AM
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-28-2025 04:24 AM
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.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-28-2025 04:49 AM - edited ā01-28-2025 04:52 AM
while initializing in variables it is giving undefined and not moving further.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-28-2025 04:54 AM
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.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-29-2025 10:59 PM
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.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader