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.

On a UI Action how can i push the prompt input in as a comment and update the record

Davie
Giga Expert

I have a UI Action which does a confirm before force closing a table record but I'd like to replace the confirm with a prompt, asking the user to enter a comment for force closure, but can't seem to get the prompt input into the comment, it shows as null

function rma_complete(){ // Same as OnClick
	var reason=prompt("Enter reason for force closure this request");
      if (reason!="")
              {
              gsftSubmit(null, g_form.getFormElement(), 'rmaclose'); 
      }
      else
              {
              return false;
      }
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
   rmagotocls();//change to next stage

function rmagotocls(){  //change to next stage, same as above
  current.work_notes = gs.getUser().getFirstName() + " " + gs.getUser().getLastName() + " has force closed this request from the '" + current.state.getDisplayValue() + "' state, reason: " + reason;	
	current.state = 300;
   current.update(); 
   action.setRedirectURL(current);
}

 

1 ACCEPTED SOLUTION

Check sample code for refernce

function rma_complete() { // Same as OnClick
    var reason = prompt("Enter reason for force closure this request");
    if (reason != " ") {
        g_form.setValue('comments', g_user.firstName + " " +reason);
        gsftSubmit(null, g_form.getFormElement(), 'rmaclose');
    } else {
        return false;
    }
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    rmagotocls(); //change to next stage

function rmagotocls() { //change to next stage, same as above
    //current.comments = "reason: " + reason;
     current.description = 'hello.testing';
    current.update();
    action.setRedirectURL(current);
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

4 REPLIES 4

Voona Rohila
Mega Patron
Mega Patron

Hi davie

I think you are trying to access "reason" variable which is in another function

Use setValue to set the reason.

Check this

https://servicenowguru.com/scripting/client-scripts-scripting/javascript-popup-boxes-servicenow/#:~:...


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Check sample code for refernce

function rma_complete() { // Same as OnClick
    var reason = prompt("Enter reason for force closure this request");
    if (reason != " ") {
        g_form.setValue('comments', g_user.firstName + " " +reason);
        gsftSubmit(null, g_form.getFormElement(), 'rmaclose');
    } else {
        return false;
    }
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    rmagotocls(); //change to next stage

function rmagotocls() { //change to next stage, same as above
    //current.comments = "reason: " + reason;
     current.description = 'hello.testing';
    current.update();
    action.setRedirectURL(current);
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

@Rohila MAGIC! Thank you

@Voona Rohila  hello I has a problem, the prompt Can I set required input items?