How to map string choice field to integer choice field using transform source script ?

Dinesh9
Giga Contributor

Hi All ,

 I am having a string choice field on import set table (table a)and i want to map the field to the target table's (table b) integer choice field.For Eg if in the import set table the status is disposed then  on the target table the value will be mapped as retired. If anyone knows please help me out.

find_real_file.png

 

Thanks,

Dinesh Kumar G

12 REPLIES 12

Hi,

I just wanted to check in on this. If my reply helped guide you correctly, please mark it as Helpful & Correct.

Thank you!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I just wanted to check-in on this.

If my reply above helped guide you correctly, please mark it as Helpful & Correct.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Luke7
Tera Expert

In addition to Allen's suggestion, you may also consider a switch statement to more cleanly handle each case without writing separate if/else statements.

 

var val;
switch (source.status) {
  case 'Deployed > Active':
  case 'Deployed':
  case 'Deployed > Inactive':
  case 'Deployed > To Be Disposed':
    val = 2;
    break;
  case 'Disposed':
    val = 1;
    break;
}

return val;

Yea, thanks. There's a multitude of ways to do it. Thanks for offering that up though.

The thing here is that if they don't know JavaScript and you're trying to do something more "fancy" then you could confuse someone, but still good to mention either way. We could all respond for days about "how" to do it, haha.

Thanks for helping


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Dinesh,

As suggested you will have to use field map script for this field in your transform map; sample script below:

you will required to add else if statement for every choice value; ensure you set choice action as ignore for the choice list field

find_real_file.png

 

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