Loading variable choices when loading variables using transform maps

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 04:25 AM
Dear team, I hope all is well!
I am working on a requirement to load data related to a certain catalog item onto the platform, the data is essentially variables relating to this catalog item as well as the choices for all the variables of the type (Select box).
I have successfully managed to load the variables against their catalog item using a transform map but I am facing the challenge of being unable to load the choices against their respective variables
I would like to avoid the method of loading the choices in a second transform map that comes after loading the variables, I would highly prefer that the variables as well as the choices are loaded in the same transform map/action
Any ideas on how I could implement that?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 04:40 AM
Hello @Tariq Alshara
One way is you can create an onAfter script on transform map. Check if the variable is of type select box and then write script to add choice values (using GlideRecord on question_choice table).
Although, the second transform map approach is much simpler I guess.
Thank you,
Ali
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 05:06 AM
Hello @Ahmmed Ali, thanks for the response!
Do you mind sharing your thoughts on how I can grab the choices if they are sitting in an Excel sheet?
I have the variables listed in an excel sheet with their choices against them, how would you script it?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 05:10 AM - edited 10-19-2022 05:17 AM
Hello @Tariq Alshara
One way is you can add choices column in your catalog variables excel sheet, but do not map that field to target field in transform map. Now in transform script, you can read the choice values using source.FIELD_NAME and then write script to create records in question_choice table.
As for script part, below is example: please validate all field names
var choices = source.getValue("YOUR_CHOICE_FIELD_NAME_IN_IMPORT_SET");
var choicesArray = choices.split("\n");
for (var i=0; i< choicesArray.length; i++){
var grChoice = new GlideRecord("question_choice");
grChoice.initialize();
grChoice.question = target.getValue("sys_id");
grChoice.text = choicesArray[i];
grChoice.value = choicesArray[i];
grChoice.insert();
}
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2022 04:43 AM
Hi @Tariq Alshara ,
For choice field which are creating new choices, you need to make choice action as ignore for that fields.
ex.
Thanks,
Pratik Malviya