- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2016 08:48 PM
Hi ,
I am looking for a code to save 2 values in the Virtual Machine CI form (cmdb_ci_vm table). Form will have fields VMname1 , IPAddress1 Similarly VMname2 , IpAddress2 ,VMname3 IpAddress3 and have to save the data filled in these fields in a table similarly with same field names.
If any of these user entered data repeats then it should throw an error .
VMname or IPAddress should not be duplicated.
Do guide me what to do.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 03:55 AM
Now, update your script include to:
var CheckVMDuplicate = Class.create();
CheckVMDuplicate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkDuplicate : function() {
var s1 = this.getParameter('sysparm_s1');
var s2 = this.getParameter('sysparm_s2');
var s3 = this.getParameter('sysparm_s3');
var gr = new GlideRecord('u_vm_info');//your table name u_vm_info
var gc = gr.addQuery('u_vm1', s1);//Make sure your field names are VM1, VM2, VM3. not titles.
gc.addOrCondition('u_vm2', s1);
gc.addOrCondition('u_vm3', s1);
if(s2 != '') {
gc.addOrCondition('u_vm1', s2);
gc.addOrCondition('u_vm2', s2);
gc.addOrCondition('u_vm3', s2);
}
if(s3 != '') {
gc.addOrCondition('u_vm1', s3);
gc.addOrCondition('u_vm2', s3);
gc.addOrCondition('u_vm3', s3);
}
gr.query();
if(gr.next())
return false;
gr.initialize(); | ||
gr.u_vm1 = s1; | ||
gr.u_vm2 = s2; | ||
gr.u_vm3 = s3; | ||
gr.insert(); |
return true;
},
type: 'CheckVMDuplicate'
});
Add these lines, it will insert the values in the table also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 01:04 AM
Hi,
Here, what you can do is:
Create UI policies to display three variables named VM1, VM2, VM3. with condition, when value of No. of VM's is 1, 2, or 3.
It will take care visibility.
Now, since you want to insert only when these values are not present in the table.
1. First, create a script include to check if the given values are present in the table required.
2. Now, make an AJAX call to that script include from an onSubmit Client script on item, which will return the status, whether or not to submit the record.
3. If true, continue submit. else return false, and throw an alert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 01:10 AM
Visibility part is already done .
Can you help me with the code as I have never written script include and AJAX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 01:20 AM
Can you please let me know the field names for the cmdb_ci_vm table. Field names, not field title.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 01:25 AM
now cmdb_ci _vm table is not in picture now . only catalog and custom table .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 01:30 AM
Ok, then, tell me the name of your custom table and related field names 'VM1', 'VM2' & 'VM3'.