How to get a dynamic choiceList for a field while creating a g_modal for a CSM/FSM Workspace?

Ahsan Zafar
Tera Contributor

I'm creating a modal for Service case table where I have one dropdown choicelist field and other is the textarea. I defined g_scratchpad in a business rule to get all the choices for the field which I further used successfully for the classic UI. Now the question is how can I use this g_scratchpad for the Workspace client script as well??

//Workspace Client Script

function onClick(g_form) {
   
    var fields = [
        {
            type: 'choice',
            name: 'resolution_code',
            label: getMessage('Resolution Code'),
            value: getMessage(' --None-- '),
            //choices: JSON.parse(g_scratchpad.resolutionCodeChoices),
            mandatory: true
        },

//Thankyou..

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Ahsan Zafar 

Is the g_scratchpad coming undefined in workspace script?

If yes then you will have to use GlideAjax, bring the choices and then populate

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

No @Ankur Bawiskar, As you can see that there is an alert statement at the bottom of the script, it is showing all the required choices as an objects. I'm just unable to use it accordingly

@Ahsan Zafar 

you are saying this line is not working?

//choices: JSON.parse(g_scratchpad.resolutionCodeChoices),

If yes then it expects value in this json format

{
"choices": [
{
"value": "myValue1",
"displayValue": "myLabel2"
},
{
"value": "myValue2",
"displayValue": "myLabel2"
}
]
}

Try giving hard-coded value and if it works then send the same values in g_scratchpad variable

I have also created a blog for something similar

Populating dynamic choices in workspace form pane for choice field type 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ahsan Zafar 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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