Can I create an UI Action button to Create a new ast_contract record

Wyatt Fudal1
Tera Guru

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.

WyattFudal1_0-1708454645641.png

 

7 REPLIES 7

Sohithanjan G
Kilo Sage
Kilo Sage

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 !! 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

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 

WyattFudal1_0-1708457964719.png

 

From UI button

WyattFudal1_1-1708458217000.png

 

 

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 !! 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

HI @Sohithanjan G 

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

createIncident();

function createIncident() {
    var contractRecord = new GlideRecord('ast_contract');
    contractRecord.initialize();
    contractRecord.substate = ('awaiting_review');
    contractRecord.support_request = 'current.sys_id';

    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);
}
 
Support Request is a reference to the u_master_contract 
WyattFudal1_0-1708531945972.jpeg

XML of the CNTR

parent contract.JPG