Facing issue in the script include json parse

Community Alums
Not applicable

I was facing issue in script include can anyone help me with this

 

script include:

var ApprovedPromo= Class.create();
ApprovedPromoEquity.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
amountEquity:function(){
var currentLevel=this.getParameter('sysparm_current_Level');
var futureLevel=this.getParameter('sysparm_future_Level');
var equityAmount=gs.getProperty('sn_hr_core.PromoAmount') || "{}";
var amountsMap=JSON.parse(equityAmount);
var equityMap=currentLevel+'_'+futureLevel;
var amount=amountsMap[equityMap];
if(amount===undefined){
return 'error';
}return amount;
 
},
 
    type: 'ApprovedPromo'
});
 
when i put gs.info message below the json.parse script line i was not getting any log but when i place the log message above the json.parse line the log is generating 
and the system property i.e..,sn_hr_core.PromoAmount' is a string type and the value is { "1_2":"USD 10",
"1_3":"USD 20",
"1_4":"USD 30" }
4 REPLIES 4

Srikanth Buddep
Tera Expert

Have you tried logging 'equityAmount' and see what value it is printing?

 

Also, try converting the value of the property to string in the parse, if the above log is printing the value.

var amountsMap=JSON.parse(equityAmount.toString());

 

Regards,

Srikanth B

Community Alums
Not applicable

@Srikanth Buddep 

It was not displaying anything in log table when i use gs.log('equityAmount') and also modifies the var amountsMap=JSON.parse(equityAmount.toString()); nothing displaying in log value

@Community Alums 

as the equityAmount is empty, parse is failing.

 Try this:

var equityAmount = gs.getProperty('sn_hr_core.PromoAmount')? gs.getProperty('sn_hr_core.PromoAmount'): '{}';

 

Regards,

Srikanth B

Sandeep Rajput
Tera Patron
Tera Patron

@Community Alums Please update your system property sn_hr_core.PromoAmount as follows. Make sure that there are no line breaks in the value.

"{\"1_2\":\"USD 10\",\"1_3\":\"USD 20\",\"1_4\":\"USD 30\"}"

 

Screenshot 2024-02-20 at 12.04.42 AM.png

Once the property value is fixed, your code will start returning the correct result.

 

Hope this helps.