Upland OL User community

Convert template JS to datamapper JS

I am trying to take this code that I have to convert a code to a full company name that is concatenating a client code and a company code to reveal the full company name. How would I convert this to use in the datamapper? I get an error saying that results is not defined.

//read in the CLIENTCODE field from the record set
var CompanyName = record.fields[“CLIENT_CD”] + record.fields[“COMPANY_CD”];

//create JSON array of Company Names and Client Codes
var clients = {
“c24001”: “ACE Property & Casualty Insurance Company”,
“c03601”: “American Heritage Life Insurance Company”,
“c53801”: “American National”,
“c57501”: “Americo Financial Life and Annuity”,
“c58001”: "Americo Financial Life and Annuity Insurance Company ",
“c53701”: “Ameriprise/Riversource”,
“c52704”: “Central States Health & Life Company of Omaha”,
“c52501”: “Central States Indemnity Co. of Omaha”,
“c56001”: “Country Life Insurance Company”,
“c21001”: “Crum & Forster”,
“c52601”: “CSI Life Insurance Company”,
“c20101”: “Elips Life Insurance Company”,
“c20501”: “Erie Family Life Insurance Company”,
“c59501”: “Everest Reinsurance Company”,
“c57601”: “Great Southern Life Insurance Company”,
“c35401”: “Jackson National Life Insurance Company”,
“c22001”: “Kemper Health”,
“c51301”: “KSKJ Life”,
“c47801”: “Lincoln Heritage Insurance Company”,
“c20001”: “Lumico Life Insurance Company”,
“c23001”: “Medica”,
“c21101”: “Monitor Life Insurance Company of New York”,
“c53401”: “Nationwide Financial”,
“c53601”: “Pacific Life”,
“c47501”: “Principal Life Insurance Company”,
“c51101”: “Puritan Life Insurance Company of America”,
“c49501”: “Royal Neighbors of America”,
“c51001”: “Shenandoah Life Insurance Company”,
“c51090”: “SBLI USA Life Insurance Company, Inc.”,
“c07101”: “State Mutual Insurance Company”,
“c11901”: “State Mutual Insurance Company”

//return full name based on it’s Client Code

What are the syntax differences between the two? I am having trouble researching what the difference is to be able to convert them.

The results object exists only in the template, hint from the .html method. In the datamapper there are only records and fields and the html (which builds up the template doesn’t exist at all).

I suppose you could create a new field FULLNAME and have it set as a javascript extraction where you simply issue clients[CompanyName] instead of the results.html

1 Like

@Maxiride is right, the results object relates to the result of the query performed by the script in the template (result set for the ‘selector’).

In DataMapper the last value attribution to a variable is the one used as the result for the field. Attached a quick sample with your clients array.

clients.OL-datamapper (4.0 KB)

1 Like

I ended up just changing the last line to clients[CompanyName]; to get it to work.