Record producer variables data update in table after created record

Nitya2
Kilo Guru

we have record producer on  custom table , after record created we have variables visible .

requriement is when those variables has to update table also has to update

i have made below code for single line text variables update in string field   - before update businessrule which is working fine .

current.setValue('u_visualization' ,current.variables.visualization_owner.getDisplayValue());

current.setValue('u_pull_quote_or_data_highlight' ,current.variables.pull_quote);

But when i try to update few checkboxes variables trying to update in string field with comma separated value its not working

kindly correct code and please help

1)    i tried in before business rule:


var checkboxes = ['ltc_financials', 'hospital_financials', 'hospital_chargemasters', 'hospital_community_benefit_plans', 'hospital_fair_pricing_policies', 'prescription_drug_rx_costs', 'healthcare_payments'];

var checkLable = ['Hospital Financials', 'LTC Financials', 'Hospital Chargemasters', 'Hospital Community Benefit Plans', 'Hospital Fair Pricing Policies', 'Prescription Drug (Rx) Costs', 'Healthcare Payments'];

for (var x = 0; x < checkboxes.length; x++) {
// if (checkboxes[x] == 'true') {


// var checkLable = current.variables.ltc_financials +',' + current.variables.hospital_financials +','+ current.variables.hospital_chargemasters +','+ current.variables.hospital_community_benefit_plans +','+ current.variables.hospital_fair_pricing_policies +','+ current.variables.prescription_drug_rx_costs +','+ current.variables.healthcare_payments;


current.setValue('u_cost_transparency', checkLable);
}

got error  like undefined, undefined, undefined

2) tried below before update business rule:

 

(function executeRule(current, previous /*null when async*/ ) {

// Add your code here

var ltc = current.variables.ltc_financials;
var hosp = current.variables.hospital_financials;
var chrge = current.variables.hospital_chargemasters;

if (ltc == 'true') {
var ltc1 = 'Hospital Financials';
gs.log('ltc' + ltc1);
}
if (hosp == 'true') {
var hosp1 = 'LTC Financials';
gs.log('hosp' + hosp1);
}
if (chrge == 'true') {
var chrge1 = 'Hospital Chargemasters';
}

var abc = ltc1 + ',' + hosp1 + ',' + chrge1;

current.setValue('u_cost_transparency', abc);

})(current, previous);

 

3) and tried in onsubmit client script:

function onSubmit() {
//Type appropriate comment here, and begin script below

var ltc = g_form.getValue('ltc_financials');
var hosp = g_form.getValue('hospital_financials');
var chrge = g_form.getValue('hospital_chargemasters');

if (ltc == 'true')
{
var ltc1= 'Hospital Financials';
}
if(hosp == 'true')
{
var hosp1 = 'LTC Financials';
}
if(chrge == 'true')
{
var chrge1 = 'Hospital Chargemasters';
}
var abc = ltc1+','+hosp1+','+chrge1;

g_form.setValue('u_cost_transparency',abc);
}

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

So you want all the values from those checkboxes to be placed in u_cost_transparency

this should work fine in before update BR

See the changes

(function executeRule(current, previous /*null when async*/ ) {

// Add your code here

var ltc = current.variables.ltc_financials;
var hosp = current.variables.hospital_financials;
var chrge = current.variables.hospital_chargemasters;

var abc = '';

if (ltc.toString() == 'true') {
abc = 'Hospital Financials';
gs.log('ltc' + ltc1);
}
if (hosp.toString() == 'true') {
abc = abc + ',' + 'LTC Financials';
gs.log('hosp' + hosp1);
}
if (chrge.toString() == 'true') {
abc = abc + ',' + 'Hospital Chargemasters';
}

current.setValue('u_cost_transparency', abc);

})(current, previous);

Regards
Ankur

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

View solution in original post

14 REPLIES 14

Last question for conversion :

if Table field in string format , but variable in date format 

1)can we update through record producer script 

 

2) how can we make through BR as well.?

Hi,

Yes you can map date value to string field.

current.string_field = producer.date_variable;

Regards
Ankur

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

When i use below code its updating  backend values , we need to update front end label names.

Because we have around 100+ variables , so would like to automate this . 

 

and  

kindly assist update checkbox valline after line 

example :

Hospital Financials
LTC Financials
Hospital Chargemasters
Hospital Community Benefit Plans
hospital fair pricing policies

var selected_checkboxes = ['ltc_financials', 'hospital_financials', 'hospital_chargemasters', 'hospital_community_benefit_plans', 'hospital_fair_pricing_policies', 'prescription_drug_rx_costs', 'healthcare_payments'];

var checkBoxLables = ['Hospital Financials','LTC Financials','Hospital Chargemasters','Hospital Community Benefit Plans','hospital fair pricing policies','prescription drug rx costs','healthcare payments'];

var variables= current.variables.getElements();

for (i=0;i<variables.length;i++){

if(selected_checkboxes.indexOf(variables[i].getName())>-1 && variables[i]=='true'){
selected_checkboxes.push(variables[i].getName());
}
}

current.setValue('u_cost_transparency',selected_checkboxes.toString());

asifnoor
Kilo Patron

Hi,

1. In your RP, why don't you map your checkbox variable with the field name. That whatever values are selected they will be stored in your table accordingly.

2. If you want to do through script,

var selected_checkboxes=[];
var variables = current.variables.getElements();
for(i=0;i<variables.length;i++) {
if(checkboxes.indexOf(variables[i].getName())>-1&& variables[i]=="true") {
selected_checkboxes.push(variables[i].getName());
}
}

 

 

May i know what can we keep here instead of xyz in above code?

current.setValue('u_cost_transparency', xyz);