Form to insert data to a new table from service portal (Widget)

itstk
Tera Contributor

I need to make a form that opens from a widget and allows me to record information to a "newtable" table. The form should show me some of the fields in the "newtable" table and with a button save the selected values from that form to the "newtable" table. All this from service portal.

Please help in giving me an idea or if you have any documentation to be able to work from there.

1 ACCEPTED SOLUTION

Yes Dynamically also it is possible with the help of "sn record picker directive"

here is the link which will help you.

https://serviceportal.io/downloads/snrecordpicker-example/

 

If somehow I helped you, then please mark my answer Correct and Helpful.

Thanks and Regards:
Siddhnath Pandey

View solution in original post

13 REPLIES 13

Please share the above code shown in snapshot

Hey Prasad,
 
I don't have exact code as I am not able to restore my instance. Here I have written a code which is same as functionality you looking for, so you can try this. 
 
HTML
<div>
 
<!-- your widget template -->
 
  <form id="myForm">
    Caller: <sn-record-picker field="username" table="'sys_user'"  search-fields="'name'" ></sn-record-picker>
 
    Short description:<br><input type="text" name="SD" ng-model="c.sd"/><br>
  Description:<br><input type="text" name="des" ng-model="c.des"/><br>
 
    <br><button type="submit" ng-click="c.test()">Create Incident</button>
   
 
<!--<br><button onclick="document.getElementById('myInput').value = ''">Create Incident</button>-->
  </form>
</div>
 
Client Script
function() {
  /* widget controller */
  var c = this;
c.test=function()
{
c.data.tempsd=c.sd;
c.data.tempdes=c.des;
 
c.server.update().then(function()
     {
alert(c.data.a);
});
 
 
}
}
 
Server Script
(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
 
if(input)
{
var gr = new GlideRecord("incident");
     gr.initialize();
gr.short_description=input.tempsd;
gr.description=input.tempdes;
 
gr.insert();
data.a=gr.getDisplayValue('number');
//gs.addInfoMessage("Incident Is Created");
 
 
}
 
})();
 

Is it possible that we take two fields from form and check it with another table, if matched then that records should be displayed after submitting form. Eg. user enter blood group and city, that should be checked with donor table if matched, that matched  records should be displayed when form submitted.

Hello Siddhnath,

I'm trying to achieve the similar requirement.

I used your code to insert record in the incident table but facing an issue-

Whenever I'm filling only the description and not the short description, my record is getting created and showing me the Info message as well.
I do want to make these two fields mandatory.
Please suggest how can I proceed, I tried to use in HTML "required" attribute but no luck.

Duration is not written in client script. How to write in client script for choice field?