Can I create an UI Action button to Create a new ast_contract record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:45 AM
The UI action button will exist on the CNTSUP (u_contract_master) table. The button will create a CNTR record. The current way CNTR records are created is fine but they want a button. I’m running into an issue with how to script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 10:52 AM - edited 02-20-2024 10:54 AM
Hi @Wyatt Fudal1
You can use below:
var contractRecord = new GlideRecord('ast_contract');
contractRecord.initialize();
// Set field values for the new contract record
contractRecord.u_field1 = current.u_field1; // Example: Set field1 to the value from the current record
contractRecord.u_field2 = 'some_value'; // Example: Set field2 to a specific value
var contractSysId = contractRecord.insert();
if (contractSysId) {
gs.addInfoMessage('New contract record created: ' + contractSysId);
} else {
gs.addErrorMessage('Failed to create a new contract record.');
}
action.setRedirectURL('/ast_contract.do?sys_id=' + contractSysId);
Make sure to replace u_field1, u_field2, and other field names with the actual field names in your u_contract_master table. You also need to adjust field assignments accordingly.
After creating this UI action script, associate it with the desired form or list layout in the CNTSUP table.
Note: Ensure that the appropriate permissions are set for the UI action to execute successfully, and consider implementing any additional validation or business logic as needed.
HIT Helpful & Mark as Accepted Solution !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 11:43 AM
Hello @Sohithanjan G
The script made the ast_contract record, thank you!! The CNTSUP should be the parent. Would I change the function to create child incident?
Example
From UI button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 08:39 PM
Hi @Wyatt Fudal1
you can add your logic to populate the fields in the new contract:
contractRecord.opened_by = current.opened_by;
contractRecord.support_request = currrent.sys_id; // If Support request is reference field
You can populate fields in new contract record by this way.
Please mark the answer as Accepted Solution !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 08:17 AM
I added both lines and tried one each and the CNTSUP doesn't become the contact parent. The support field remains blank. Am I implementing the code wrong? Thank you so much for your assistance.
Current code
XML of the CNTR