The CreatorCon Call for Content is officially open! Get started here.

Not able to save get data from client script on server side. Need Help

Naveed_Hussain
Kilo Guru

Hi Community,

 

I have create a widget as shown in the image.  I want to get data from those html fields and save into my table. But it's working fine on client script and having issue with server script. When I click on the submit button data is save with undefine values into the required table.

 

Another issue: When form is loaded the undefine values are automatically save into the table.

 

html code:

<div class="fields-container">
  <label>Roll No:</label><br>
  <input type="number" id="roll_no" name="rollNo" ng-mode=""><br>
  <label >Student Name:</label><br>
  <input type="text" id="student_name" name="Name" ng-model="c.name"><br>
  <label>Father Name:</label><br>
  <input type="text" id="father_name" name="FatherName" ng-model="c.fname"><br>
  <label >Program:</label><br>
  <input type="text" id="program" name="Program" ng-model="c.program">
  <center>
  <button ng-click="c.submit()">
    Submit
  </button>
  </center>
</div>

 

client script code:

api.controller=function() {
  /* widget controller */
  var c = this;
	
	c.submit=function()
	{
		c.data.Name=c.Name;
		c.data.FatheName=c.fname;
		c.data.Program=c.program;
		c.server.update();

	}
};

 

Server Script:

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

	var gr = new GlideRecord("u_student_portal_table");
	gr.initialize();
	gr.setValue('u_name', input.Name);
	gr.setValue('u_father_name', input.FatherName);
	gr.setValue('u_program', input.Program);
	gr.insert();
	
	
})();

 

 

Naveed_Hussain_0-1681482943477.png

 

1 ACCEPTED SOLUTION

Prince Arora
Tera Sage

@Naveed_Hussain ,

 

Can you  update server side script as follows and try again!

 

if(input){
var gr = new GlideRecord("u_student_portal_table");
gr.initialize();
gr.setValue('u_name', input.Name);
gr.setValue('u_father_name', input.FatherName);
gr.setValue('u_program', input.Program);
gr.insert();
}

 

I have noticed their is one more issue in client side:

 

c.submit=function()
{
c.data.Name=c.Name; // it should be c.name
c.data.FatheName=c.fname;
c.data.Program=c.program;
c.server.update();

}

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

View solution in original post

2 REPLIES 2

Prince Arora
Tera Sage

@Naveed_Hussain ,

 

Can you  update server side script as follows and try again!

 

if(input){
var gr = new GlideRecord("u_student_portal_table");
gr.initialize();
gr.setValue('u_name', input.Name);
gr.setValue('u_father_name', input.FatherName);
gr.setValue('u_program', input.Program);
gr.insert();
}

 

I have noticed their is one more issue in client side:

 

c.submit=function()
{
c.data.Name=c.Name; // it should be c.name
c.data.FatheName=c.fname;
c.data.Program=c.program;
c.server.update();

}

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Thanks Man