Inbound Action help: need to extract the next line after a specific word in email body

booher04
Tera Guru

I have an inbound action working well for new emails but the FWD is not working.  I need a way to extract/parse the string in the line after a specific line: App Name.

 

Here is the code I have that is working for NEW inbound actions but not FWD:

	createRequest();
function createRequest() {

	var cartId = GlideGuid.generate(null);
	var cart = new Cart(cartId);
	var item = cart.addItem('acfb58a73bec6e100d0f8c9c24e45aa0'); 
	
	var emailBody = email.body_text;
	var lines = emailBody.split('\n');
	var firstLine = lines[27];
	var appBody = firstLine.replace("App Name", "");

	cart.setVariable(item, 'email_subject', email.subject);
	cart.setVariable(item, 'email_body',email.body_text );
	cart.setVariable(item, 'app_name', appBody);

	gs.log ('Test: ' + email.subject + ': ' + email.body_text);
	gs.log('APPBODY: ' + appBody);

	var rc = cart.placeOrder();


	var grRITM = new GlideRecord('sc_req_item');
	
	grRITM.addQuery('request',rc.getValue('sys_id'));
	grRITM.query();
	
	if(grRITM.next()) {
			
		grRITM.setValue('sys_created_by', ' Inbound Email Action');
		grRITM.setValue('contact_type', 'email');
		//grRITM.setValue('short_description', '"Multifactor Authentication Compliance"' + current.variables.app_name);
		grRITM.setValue('description', email.body_text);
		grRITM.setValue('assignment_group','bddd7a5497c681909419b4e3f153af0b');
		//Add Attachment(s)
		
		GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'sc_req_item', grRITM.sys_id);
		
				
		grRITM.update();
				
		var emailGR = new GlideRecord("sys_email");
		emailGR.addQuery("sys_id", sys_email.sys_id);
		emailGR.query();
		if(emailGR.next()){
			emailGR.instance = grRITM.sys_id;
			emailGR.target_table = "sc_req_item";
			emailGR.update();
					
		}
			}
}

I need to be able to find "App Name" on the email body and extract the very next line as the email format has it like:

App Name:

"xxxxxxx"