logo

NJP

Create Incident Widget

Import · Feb 20, 2020 · article

Create a widget as shown below to submit an incident:

image

Follow below Steps:

1. Navigate to Service Portal => Service Portal Configuration

image

2. Click on Widget Editor

image

3. Click on Create New Widget

image

4. Fill Widget Name and Submit

image

5. Now Use Below HTML Script:

<div class ="panel panel-default">
   <div class="panel-heading">
         <h4 class="panel-title">
           Create an Incident   
         </h4>    
  </div>
  <div class="panel-body">
    <form>
      <div class="form-group">
        <lable for=issue>Issue</lable>
        <input type="text" class="form-control" 
               id="issue" 
               placeholder="Please enter issue"
               ng-model="data.newIncident.issue"/>
      </div>
      <div class="form-group">
        <lable for="urgency" >Urgency</lable>
        <select id="urgency" 
                class="form-control"
                ng-model="data.newIncident.urgency">
          <option value="1">High</option>
          <option value="2">Medium</option>  
          <option value="3">Low</option>  
        </select>

      </div>     
    </form>
  </div>

     <div class="panel-footer">     
        <button class="btn btn-success" ng-click="c.submit()"> Submit  
          </button>
      </div>
    </div>

6. Use below Client Script:

function() {
  /* widget controller */
  var c = this;
c.submit =function(){
    c.data.action='createIncident';
    c.server.update();
}
}

7. Use Below Server Script

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */

data.newIncident={
    issue:'',
    urgency:''
}

    if(input && input.action ==="createIncident")
        {
            createIncident(input.newIncident);
        }
    function createIncident(inc)
    {
        var gr=new GlideRecord('incident');
        gr.newRecord();
        gr.setValue('caller_id',gs.getUserID());
        gr.setValue('short_description',inc.issue);
        gr.setValue('urgency',inc.urgency);
        gr.insert();
    }


})();

Now if you access preview this widget it will look as below and will give you an ability to Submit a new incident.

image

References : docs.service-now.com, www.udemy.com , https://getbootstrap.com/docs/3.3/components/

Please mark helpful if this article helps !!

Regards,

Ajay

View original source

https://www.servicenow.com/community/developer-articles/create-incident-widget/ta-p/2300920