Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to set value of choice field in transform map?

Ashwini Jadhao
Giga Guru

Hi,

I am setting  value of choice field in transform map with script as below but it is not working it will set value as 2-Medium always .

(function transformRow(source, target, map, log, isUpdate) {
if (source.priority== 'High') {
target.priority == gs.setValue("target.priority",1);//1 is 1 - High
}else if (source.priority== 'Medium') {
target.priority== gs.setValue("target.priority",2);// 2 is 2-Medium
}else if (source.priority== 'Low') {
target.priority== gs.setValue("target.priority",3);//3 is 3-Low
}

// Add your code here

})(source, target, map, log, action === "update");

1 ACCEPTED SOLUTION

Dhananjay Pawar
Kilo Sage

Hi,

 

(function transformRow(source, target, map, log, isUpdate) {


var priprityVal=source.getValue('priority');
if(priprityVal=='High')
{
target.priority ='1';
}
else if(priprityVal=='Medium')
{
target.priority ='2';
}
else
{
target.priority='3';
}

})(source, target, map, log, action==="update");

 

Thanks,

Dhananjay

View solution in original post

6 REPLIES 6

Jaspal Singh
Mega Patron
Mega Patron

Try using below.

(function transformRow(source, target, map, log, isUpdate) {

gs.log('Source priority is ',source.priority);//check in logs
 
if (source.priority== 'High') {
target.priority ='1'; //make sure  you pass the dictionary value here for priority
}else if (source.priority== 'Medium') {
target.priority= '2';// make sure  you pass the dictionary value here for priority
}else if (source.priority== 'Low') {
target.priority='3';//make sure  you pass the dictionary value here for priority
}

// Add your code here

})(source, target, map, log, action === "update");

 

Thanks but it is not working

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

how the value is present in the incoming data i.e. import set table; you can use field map script for this; choice action as ignore

Note: ensure you compare proper values in if condition with the incoming values; also use proper source field

I believe it should be u_priority and not priority

answer = (function transformEntry(source) {

	// Add your code here
var targetValue = '';	

var sourcePriority = source.u_priority;
if(sourcePriority == 'High')
targetValue = 1;
else if(sourcePriority == 'Medium')
targetValue = 2;
else if(sourcePriority == 'Low')
targetValue = 3;


})(source);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

I have checked all names and values.Those are priority only