Appending Lookup Field to Subject

Appending Lookup Field to Subject

Hi, 

Similar to Appending field (manageengine.com) on form submission I'd like to update the subject to the value based on a look up field. I can't seem to get the right coding, I'm assuming I need to set variables to look up the first & last names of the lookup field, but I'm not a coder so I can't get my head around it. 

We have a leavers template request, and when submitting the form the requestor can only pick from a list of active accounts, which works great, how do I then pass that variable through in a script to rename the ticket to "Leaver - LEAVERSNAMEBASEDONLOOKUP - Last day dd/mm/yy" 

The date field works perfectly, but my output in tickets is "Leaver - Null - Last Day 31/05/2024"

My code is currently the below, I know I need to query the lookup field for the first name last name but I can't figure out how

// SET APPROPRIATE UDF KEY in lower cases and Default Subject prefix
var subjectPrefix = "Leaver - ";
var leaver = await CS.getValue("udf_fields.udf_ref3");
var lastdaystring = await CS.getValue("udf_fields.udf_date4");
var lastday = new Date(lastdaystring.value).toLocaleDateString('en-GB');
CS.setValue("subject",subjectPrefix + leaver + " Last Day - " + lastday);
CS.end();

Thanks!

                New to ADSelfService Plus?