+ Start a Discussion
golugolu 

relacing a sting in javascript

Hi,

I am retrieving the email templates and showing in my lightning component. Currently the email template body in the component is displaying {!Contact.FirstName}. I want to replace it with recordId.name. Can anyone please help me with that?

Code for javascript controller
({
	doinit: function (component, event, helper) {
        
		var smsTemplatesAction = component.get("c.getSMSTemplates");

		smsTemplatesAction.setCallback(this, function (response) {
			var state = response.getState();
			var templates = response.getReturnValue();
			if (state === "SUCCESS") {
				var templateList = [];
				templateList.push({ "class": "optionClass", label: 'Select Value', value: '' });
				for (var key in response.getReturnValue()) {
					templateList.push({ "class": "optionClass", label: templates[key].Name, value: key });
				}
				component.find("selectTemplate").set("v.options", templateList);
			}
		});

		$A.enqueueAction(smsTemplatesAction);

		var charLimitAction = component.get("c.getCharacterLimit");
		charLimitAction.setCallback(this, function (response) {
			var state = response.getState();
			if (state === "SUCCESS") {
				component.set("v.charLimit", response.getReturnValue());
				component.set("v.charsRemaining", response.getReturnValue());
			}
		});
		$A.enqueueAction(charLimitAction);

	},
	fetchbody: function (component, event, helper) {
		var templateId = component.find('selectTemplate').get('v.value');
		var templateBody;
        var recordId = component.get("v.recordId.name");
		if (templateId == '') {
			templateBody = '';
		}
		else {
			var smsTemplatesAction = component.get("c.getSMSTemplateById");

			smsTemplatesAction.setParams({
				"templateId": templateId
			})

			smsTemplatesAction.setCallback(this, function (response) {
				var state = response.getState();
                
				if (state === "SUCCESS") {
                    
					templateBody = response.getReturnValue();
                    console.log(templateBody);
                    component.set("v.selectedTemplateBody", templateBody);

					var charLimit = component.get("v.charLimit");
					var textarealength = templateBody.length;
					if (textarealength != '' || textarealength != null) {
						var totalmax = charLimit - textarealength;
						component.set('v.charsRemaining', totalmax);
					}
				}
			});

			$A.enqueueAction(smsTemplatesAction);
		}
	},
})

Please check the fetchBody function.