Post response from suitelet to client script

I have a client script that runs on fieldChanged on the item sublist on the sales order record. When filling out a custom field in the sublist, a search runs on item. If we get > 1 hit for items we want a popup message to display where the user has to select an item. When they have selected the item from the popup, it should populate the item field.

To accomplish this I have created a Suitelet for the popup. Everything works well, the popup displays, and the select field displays the items. But I cannot seem to find how to post back the item selected to the client script, or how to populate the item field in the sublist once an item was selected..

Here is my sample code:

Client script opens the suitelet window this way:, ‘socialPopupWindow’, ‘location=no,width=500,height=500,scrollbars=yes,top=600,left=450,resizable = no’)
if (context.request.method === ‘GET’) {
const itemArray = JSON.parse(context.request.parameters.custscript_itemarray)
    const form = ui.createForm({
        title: ‘Select Item’,
        hideNavBar: true
        label: ‘Ok’
    const selectItem = form.addField({
        id: ‘custpage_select_item’,
        label: ‘Select Item’,
        type: ui.FieldType.SELECT,
    addSelectOptions(selectItem, itemArray)
    context.response.writePage({ pageObject: form })
} else if (context.request.method === ‘POST’){
const item = context.request.parameters.custpage_select_item
//to post back I have tried different methods, for example:
            name: ‘selectedItem’,
            value: item
//3 – tried to post with this method for example
context.response.write(<html><body><script>window.opener.setValue({ fieldId: ‘memo’, value: ‘TEST’ });window.close();</script></body></html>)
Is there any way to have the client script wait for the response? Seems like it could work with runtime.getCurrentSession().set/get. But the client script finishes before I select anything in the popup. Or any other solution of calling the suitelet popup and getting the response?
Rookie Asked on October 22, 2021 in SuiteScript.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor