Where will use the onChoiceCreate transform map script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2019 01:30 PM
Hi all
Where will we use onChoiceCreate transform map script.
Give me one example
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2019 10:31 PM
Hi Rahul,
One such example is -
There a choice type field and you want that when a new choice is inserted then a record in a remote table is created. To accomplish the same you need to write a on choice create script.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2019 12:41 AM
Hi Rahul,
When: The onChoiceCreate event script is processed at the start of a choice value creation, before the new choice value is created.
| Import Set JS object | Type | Context in the onChoiceCreate import set event |
|---|---|---|
| source | GlideRecord | The row of the source table that is currently being processed. |
| target | GlideRecord | The row of the target table that is currently being processed. |
| map | GlideTransformMap | Read-only information about the current transform map record. |
| log | Function | The log object for the current import run. For example, log.info(...), log.warn(...), log.error(...). |
| action | String | Action returns a value of either "insert" or "update" indicating whether the current target row is about to be created or updated. |
| name | String | Evaluates to the field name of the target record for which a choice value is about to be created. |
| value | String | Evaluates to the display value from the source record for which a choice is about to be created. |
| ignore | Boolean | When set to true, ignores the creation of a choice value. |
| error | Boolean | When set to true, rejects the entire transformation row, no data is saved for this row. |
Example:
//Create an event
var e = new GlideEvent("myimport_ChoiceCreate", action, value, "");
e.insert();
for more detail please go through link
https://docs.servicenow.com/bundle/jakarta-platform-administration/page/script/server-scripting/refe...
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2019 12:58 AM
Hi,
ON CHOICE CREATE
This gets executed when a new choice is added on the transform. This transform script is triggered before the choice value is created in case there's any preparation, clean-up, preconditions, etc... for the new choice to properly exist.
Variables: source, target, map, log, action, name, value, ignore, error
Summary: onChoiceCreate runs before a new choice is created on a choice field. Since this script runs when a choice is created, “create” has to be selected as the choice action for that field map. If it is not selected, the script will not run. Because onChoiceCreate is a before action, only the source table record has set values. Similar to onForeignInsert, the onChoiceCreate script can take additional action when a new choice is created on a field.
Mark it as correct/helpful,if it helps.
Regards,
Ragini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2019 01:58 PM
Thanks,
Rahul Kumar

