- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2019 04:51 AM
Based on the value(Account Name) from input radio buttons I wanted to get the details of the particular account from server side and display it in the server side. But I was unable to do that.
HTML:
<div>
<input type="radio" ng-model="c.data.acc" value="ABOF"/>ABOF</br>
<input type="radio" ng-model="c.data.acc" value="SOC"/>SOC</br>
<button ng-click="c.buttonclick()">Submit</button>
</div>
Client Script:
function() {
/* widget controller */
var c = this;
c.buttonclick = function()
{
var number=c.data.acc;
c.server.update().then(function()
{
});
alert(c.data.number+" "+c.data.phone);
}
}
Server Script:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var account= new GlideRecord('customer_account');
if(account.name== input.acc)
{
data.number=account.number;
}
})();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2019 06:39 AM
The code, which you posted contains some errors, mostly in the server side code. You don't posted 'customer_account' table. So I describe the idea of required changes on example of 'sys_user' table. The user table has user_name filed, for example, which values one can use as values of radio buttons:
<div>
<input type="radio" ng-model="c.data.acc" value="george.washington"/>George Washington<br/>
<input type="radio" ng-model="c.data.acc" value="abraham.lincoln"/>Abraham Lincoln<br/>
<button ng-click="c.buttonclick()">Submit</button>
</div>
The client side code
function () {
var c = this;
c.buttonclick = function () {
c.server.update().then(function () {
alert(c.data.acc + " has phone " + c.data.number);
});
};
}
will call c.server.update method. The server code should use input.acc filled on the client side by radio button to search in sys_user table by user_name = input.acc and to fill data.number to the field, which exist in the table. In the same way you can fill other properties of data based on fields of the table:
(function () {
if (input != null) {
console.log(input);
var account = new GlideRecord("sys_user");
// search the user by input.acc
account.addQuery("user_name", input.acc);
account.query();
if (account.next()) { // get the first record of results
data.number = String(account.mobile_phone);
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-20-2019 06:39 AM
The code, which you posted contains some errors, mostly in the server side code. You don't posted 'customer_account' table. So I describe the idea of required changes on example of 'sys_user' table. The user table has user_name filed, for example, which values one can use as values of radio buttons:
<div>
<input type="radio" ng-model="c.data.acc" value="george.washington"/>George Washington<br/>
<input type="radio" ng-model="c.data.acc" value="abraham.lincoln"/>Abraham Lincoln<br/>
<button ng-click="c.buttonclick()">Submit</button>
</div>
The client side code
function () {
var c = this;
c.buttonclick = function () {
c.server.update().then(function () {
alert(c.data.acc + " has phone " + c.data.number);
});
};
}
will call c.server.update method. The server code should use input.acc filled on the client side by radio button to search in sys_user table by user_name = input.acc and to fill data.number to the field, which exist in the table. In the same way you can fill other properties of data based on fields of the table:
(function () {
if (input != null) {
console.log(input);
var account = new GlideRecord("sys_user");
// search the user by input.acc
account.addQuery("user_name", input.acc);
account.query();
if (account.next()) { // get the first record of results
data.number = String(account.mobile_phone);
}
}
})();