- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 02:47 AM - edited 12-29-2023 07:45 AM
Hi friends,
I am creating insert a record. When the user clicks the record will be created in the custom table.
There is a reference field Instrument.
function insertDetails(){
var grInsert = new GlideRecord("u_details_data");
grInsert.initialize()
grInsert.u_instrument_manufacturer = "Lenovo";
// Inserting other variables
gr.insert();
Thank you
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 02:51 AM
Hello @Asmita7 ,
You can give a try to the code below and let me know how it works for you.
function insertDetails() {
var grInsert = new GlideRecord("u_details_data");
grInsert.initialize();
// Set the reference field to the manufacturer details record
grInsert.u_instrument_manufacturer = getManufacturerSysID("Lenovo");
// Set other variables
grInsert.some_other_field = "Some value";
// Insert the record
if (grInsert.insert()) {
gs.addInfoMessage("Record inserted successfully");
} else {
gs.addErrorMessage("Failed to insert record");
}
}
// Function to get the Sys ID of the manufacturer details record based on the name
function getManufacturerSysID(manufacturerName) {
var grManufacturer = new GlideRecord("u_manufacturer_details");
if (grManufacturer.get("u_name", manufacturerName)) {
return grManufacturer.sys_id;
} else {
gs.addErrorMessage("Manufacturer not found: " + manufacturerName);
return null;
}
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 03:43 AM
Hi @Asmita7
Here
grInsert.u_instrument_manufacturer = "Lenovo";
Instead of providing Lenovo , If you paste the sys_id of the lenovo it will work fine
If it helps please click Accept as Solution/hit the Thumb Icon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 04:12 AM
Hello @Asmita7,
Please use the below code to fulfil your requirement:
function insertDetails(){
var grInsert = new GlideRecord("u_details_data");
grInsert.initialize()
grInsert.u_instrument_manufacturer = "Put the har-coded sys_id of the Lenovo record";
grInsert.insert();
}
If the above solution resolve your issue, Please mark the solution as 'Accepted Solution' and also mark it as 'Helpful'.
Thank You!
Prathamesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2023 05:32 AM
Hello @Asmita7 ,
If my previous response helps in your issue to be resolve. Please mark my previous response as 'Accepted Solution'.
Thank You!
Prathamesh.