Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Update selected with input from dialog window

Miriam Berg
Kilo Guru

Hi,

In short: I'm trying to update selected list items using a UI Action + UI Page, but the processing script doesn't run properly.

When standing in the list view and having one or more items selected, I want to open a popup that asks the user for a company when a UI Action is clicked. That company should then be added or removed depending on the UI Action (Add Company or Remove Company).

I have the popup showing but when clicking OK, the Processing Script is not being run properly. What am I missing? Shouldn't I have access to the variables from the HTML?

Tried using a <g:ui_form> because it said on the wiki that it should be able to use the processing script, but... the only thing it did was to redirect to a full-size version of the UI Page.

Thanks in advance for any ideas.

BR /Miriam

UI Action "Add Company"

Script

function getCompany() {

  var gDialog = new GlideDialogWindow("dialog_get_company");

  gDialog.setTitle('Add Company');

  gDialog.setWidth("300");

  gDialog.render();

}

UI Page "dialog_get_company"

HTML

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:ui_form>

  <g:evaluate>

  var currentTable = RP.getWindowProperties().get('table_name') || '';

  var sysIdList = RP.getWindowProperties().get('sys_id_list') || '';

  </g:evaluate>

  <input type="hidden" name="current_table" value="$[currentTable]" />

  <input type="hidden" name="sys_id_list" value="$[sysIdList]" />

  <table width="100%">

  <tr>

  <td>

  <g:ui_reference name="company_name" table="core_company"/>

  </td>

  </tr>

  <tr id="dialog_buttons">

  <td>

  <br></br>

  <g:dialog_buttons_ok_cancel ok="return checkValue()" ok_id="ok_button" />

  </td>

  </tr>

  </table>

</g:ui_form>

</j:jelly>

Client Script:

function checkValue(){

  var company = gel("company_name");

  if(company.value == ""){

  return false;

  }

  GlideDialogWindow.get().destroy();

  return true;

}

Processing Script:

addCompany();

function addCompany() {

  var choice = new GlideRecord(current_table);

  if (sys_id_list) {

  var selectedRecords = sys_id_list.split(',');

  choice.addQuery('sys_id', selectedRecords);

  }

  choice.query();

  while (choice.next()) {

  gs.addInfoMessage(choice.value);

  add(choice);

  }

  refresh();

}

function refresh() {

  var urlOnStack = GlideSession.get().getStack().bottom();

  response.sendRedirect(urlOnStack);

}

function add(choice){

// var company = usr.u_org_company.toString();

  var list = choice.u_suppliers;

  //If the list is empty

  if (list == '') {

  list = company;

  }

  //Else - the list is not empty.

  //Does it include my company?

  else if(list.indexOf(company) < 0) {

  list = list + ',' + company;

  }

  choice.u_suppliers = list;

  choice.update();

  //action.setRedirectURL(current);

}

1 ACCEPTED SOLUTION

Yay!



Found the code to properly send over the correct info from the UI Action:



This should be in the UI Action:


gDialog.setPreference('current_table', g_list.getTableName());


gDialog.setPreference('sys_id_list', g_list.getChecked());



😆


View solution in original post

5 REPLIES 5

Miriam,


I've tried to use your solution here for another purpose. I was wondering if you could look at my post Create a metric from a dialog window asking for date/time and see if you could assist me as well.