how to add incident to incident list from widget

akshay parekar1
Tera Contributor

Hello, last step is remaining for my one portal task, please help to achieve this

Earlier i have created a widget on my portal which is showing list of opened incidents by current logged in user.

Also have added one 'NEW' button which will redirect to another widget. This second widget has User ID and short description fields. User Id is getting populated with current user's user name and short description i will put something.There is 'Submit' button also in second widget . when this  2 fields are filled and i click on submit button , this record will get updated in incident list as this incident is opened by current logged in user. As soon as i click on submit button of second widget , i must be able to see this record added to list of my first widget also.

Please tell me where i have to make changes

First widget (getting list of opened incidents by current user)-

Server script-

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
    
data.incident=[];
    
    var gr= new GlideRecord('incident');
    gr.addQuery('opened_by',gs.getUserID());
    gr.query();
    while(gr.next()){
        var incident_data={};
        incident_data.number= gr.getValue('number');
        incident_data.short_description= gr.getValue('short_description');
        incident_data.priority= gr.getDisplayValue('priority');
        incident_data.state= gr.getDisplayValue('state');
        
        data.incident.push(incident_data);
    }
})();

HTML Template-

<div>
<!-- your widget template -->
  <table border ="1.5 px">
    
    <div style="text-align:right;">
<button onClick="location.href='?id=add_incident_1'">New</button>
</div>
    
    <tr> <th style="width:120px";> Incident Number </th>
      <th style="width:120px";> Short Description </th>
      <th style="width:120px";> Priority </th>
      <th style="width:120px";> State </th>
    </tr>
    
    <tr ng-repeat ="incident_data in data.incident" > <td>{{incident_data.number}} </td>
      <td>{{incident_data.short_description}} </td>
      <td>{{incident_data.priority}} </td>
      <td>{{incident_data.state}} </td>
    </tr>
  </table>
</div>

Second widget( to add record in incident table)-

server script-

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

Html-

<div>
<!-- your widget template -->
<h1>
  Please fill the form:
  <br> <br>   
  User ID: 
<input type="text" ng-model="data.loggedinuser" size="50">
<br> <br>  
Short
Description:
<input type="text"  size="100"> 
   <br> <br>   
   <div style="text-align:left;">
<button onClick="location.href='?id=task_page'">Submit</button>
</div>
  </h1>
</div>

1 ACCEPTED SOLUTION

@akshay parekar sure mark this answer correct if it helped you and close the thread so that it helps other users with same query 

View solution in original post

7 REPLIES 7

Thanks for replying, i'm making these changes to mine script

@akshay parekar sure mark this answer correct if it helped you and close the thread so that it helps other users with same query 

yup, that has worked for me ,i am marking it as correct.

Thanks for your time!!