Use HTML Value in the Server Script - Widget

PaKe
Kilo Sage

Hi,

I have a simple widget which inserts a record after I click on the button. My problem is that I can't get the values of the HTML Fields to also insert them. I want to insert the value of the Date- and the Time-field and also the textarea.

Here my code: 

HTML Template

<div class="panel panel-{{::options.color}} category-widget no-border">
  <div class="panel-primary panel-heading">
      <h4 class="panel-title">${Request a Maintenance}</h4>
  </div>  
  <div class="panel-body">
    <table style="width:100%">
      <tr>
        <td><b>${User}: </b><label>{{c.data.user}}</label></td>
        <td><b>${E-Mail}: </b><label>{{c.data.usermail}}</label></td>
      </tr>
      <tr>
        <td><b>${Mobile number}: </b><label>{{c.data.usermobile}}</label></td>
        <td><b>${Company}: </b><label>{{c.data.usercompany}}</label></td>
      </tr>
    </table>
    <div>
      <b>${Relevant Machine}: </b>
      <label>{{c.data.machine}}</label>
    </div>
    <div>
      <label>
   			 <b>${Desired Date}: </b> 
    		<input id="date" type="date" class="dates">
			</label>
    </div>
    <div>
      <label>
   			 <b>${Desired Time}: </b> 
    		<input id="time" type="time" class="time">
			</label>
    </div>
    <div>
      <b>${Additional comments}:</b>
      <div>
        <textarea id="comments" class="textarea"></textarea>
      </div>
    </div>
    <div>
      <button class="btn btn-primary rounded m-l-lg padder-xl" ng-click="c.uiAction('submit')">
        ${submit}
      </button>
    </div>
  </div> 
</div>

Client Script:

function($scope) {
  /* widget controller */
   var c = this;
	 c.uiAction = function(action) {
     c.data.action = action;
     c.server.update().then(function() {
       c.data.action = undefined;
     })
   }
}

Server Script:

(function() {
  /* populate the 'data' object */
  /* e.g., data.table = $sp.getValue('table'); */
	
	data.user = gs.getUserDisplayName();
	data.usermail = gs.getUser().getEmail(); 
	data.usermobile = gs.getUser().getRecord().getDisplayValue('mobile_phone');
	data.usercompany = gs.getUser().getRecord().getDisplayValue('company');	
	asset_id = gs.action.getGlideURI().get('sysparm_id');
	
	var gr = new GlideRecord('u_lh_asset');
	gr.addQuery('sys_id', asset_id);
	gr.query();
	while(gr.next()){
		data.machine = gr.getValue('display_name');
		data.asset = gr.a;
	}
	
	if (input.action == 'submit') {
    // Insert Event
		var gr2 = new GlideRecord('u_lh_eventform');
		gr2.initialize();
		gr2.u_asset.setDisplayValue(asset_id);
		gr2.u_description = 'Request Maintenance';
		gr2.u_additional_comments = /*Value Textarea*/;
		gr2.u_desired_date = /*Value Date*/;
		gr2.u_desired_time = /*Value Time*/;
		gr2.insert();
	}
	
})();
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please check below link

https://community.servicenow.com/community?id=community_question&sys_id=80d17cf5db1d6b00107d5583ca96...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you but this doesn't help me. Do you have a different suggestion?