How to convert choice field (1-20) into object so that if the quantity is 6 then 6 task should creat

jyotisaroj
Tera Contributor

Hi,

I have a requirement where i need to convert the choice field called as quantity which has a choices from 1-20 into object so that the number of task should get created as same as quantity selected in catalog.
If there is another ways to achieve this please let me know.

Thank you!

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@jyotisaroj Extract the value of the choice list variable in a business rule/server side script. Run a for/while loop to generate required number of tasks can be generated.

 

Here is an example script for a business rule.

 

if (current.variables.quantity) {
    var quantity = parseInt(current.variables.quantity);
    for (var i = 1; i <= quantity; i++) {
        var task = new GlideRecord('sc_task');
        task.initialize();
        task.request_item = current.sys_id;
        task.short_description = 'Generated Task ' + i;
        task.assignment_group = 'REPLACE_WITH_GROUP_SYS_ID';
        task.insert();
    }
}