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.

prompt user to enter data

sigmachiuta
Kilo Guru

Is there a javascript popup prompt   for a user to enter data? and then use that input from the user to populate a field on a form?

10 REPLIES 10

Brian Dailey1
Kilo Sage

Try this:



var userInput = prompt("Please enter your value");


g_form.setValue('myFieldName', userInput);





-Brian



I am not sure why but I am not getting the prompt box to show, i should mention that this is a UI Action on a request item in the Self service view.


function checkCancel(){


  if(g_form.getValue('u_cancel_reason') == ''){


  var userInput = prompt("Please enter your reason");  


g_form.setValue('u_cancel_reason', userInput);  


g_form.setDisplay('u_cancel_reason',true);


g_form.setMandatory('u_cancel_reason',true);


    }


      else {


  var answer = confirm("Do you want to cancel this Item?");


  if(answer == true){


  gsftSubmit(null, g_form.getFormElement(), 'req_cancel');


  }



  }


}


  current.state= 3;


  current.stage = 'Request Cancelled';


    //get workflow helper


  var workflow = new Workflow();


  //cancel all the workflows, where current is a task record with a workflow context


  workflow.cancel(current);


  gs.addInfoMessage(gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));


  current.update();


Hi,



Is this your completed UI action code. Can you refer the below blog as reference and adjust your code


http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/


no sorry i had trouble posting the code please see above, it was working with just an alert (if a cancel reason was entered) but the problem ESS users cant modify a REQITM after it is submitted so i need a way for them to enter a cancel reason in a prompt and push that to the   form.