Using a custom label inside a string throws "Field Integrity Exception" - salesforce

I want to use a custom label inside a list that I then bind to a multi picklist.
<aura:attribute name="genderOptions" type="List"
default="[
{'label': {!$Label.c.DM_Gender_Male},'Value':
'Male'},
{'label': {!$Label.c.DM_Gender_Female}, 'value':
'Female'}
]"
/>
When I try to save the component, then I get the following exception (FIELD INTEGRITY EXCEPTION)
Failed to save DMSegmentation.cmp: Cannot mix expression and literal string in attribute value, try rewriting like {!'foo' + v.bar}: Source
Can someone help me to resolve this ?

Actually it is possible to create this inside the component. The two things you were missing are:
Quotes " need to be represented as XML escape entities.
Open and closing braces { } need to be represented as custom labels.
The component:
<aura:component >
<aura:attribute
name="genderOptions"
type="List"
default="{! ' [ '
+ $Label.c.LEFT_CURLY_BRACKET
+ '"' + 'label' + '"'
+ ' : ' + '"' + $Label.c.DM_Gender_Male + '"'
+ ' , ' + '"' + 'value' + '"'
+ ' : ' + '"' + 'Male' + '"'
+ $Label.c.RIGHT_CURLY_BRACKET
+ ' , '
+ $Label.c.LEFT_CURLY_BRACKET
+ '"' + 'label' + '"'
+ ' : ' + '"' + $Label.c.DM_Gender_Female + '"'
+ ' , ' + '"' + 'value' + '"'
+ ' : ' + '"' + 'Female' + '"'
+ $Label.c.RIGHT_CURLY_BRACKET
+ ' ] '
}"
/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
The custom labels:
<?xml version="1.0" encoding="UTF-8"?>
<CustomLabels xmlns="http://soap.sforce.com/2006/04/metadata">
<labels>
<fullName>LEFT_CURLY_BRACKET</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>LEFT CURLY BRACKET</shortDescription>
<value>{</value>
</labels>
<labels>
<fullName>RIGHT_CURLY_BRACKET</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>RIGHT CURLY BRACKET</shortDescription>
<value>}</value>
</labels>
<labels>
<fullName>DM_Gender_Male</fullName>
<language>en_US</language>
<protected>false</protected>
<shortDescription>DM_Gender_Male</shortDescription>
<value>♂</value>
</labels>
<labels>
<fullName>DM_Gender_Female</fullName>
<language>zh_CN</language>
<protected>false</protected>
<shortDescription>DM_Gender_Female</shortDescription>
<value>♀</value>
</labels>
</CustomLabels>
A client-side controller to get the value of the attribute and log it in the console:
({
doInit :
function( component , event , helper ){
var list = component.get("v.genderOptions")
console.log( list )
console.log( JSON.parse( list ) )
}
, f :
function(){
}
})
The logged result:

I found the solution. The only solution is to access these list through the client side controller available in the bundle and then populate it with the custom labels. Otherwise, lightning does not allow you to use custom labels inside lists created in the component. Have to use the doInit method for this
({
doInit: function(component, event, helper) {
var values = [
$A.get("$Label.c.DM_Gender_Male"),
$A.get("$Label.c.DM_Gender_Female")
];
component.set('v.genderOptions', values);
}
})

Related

SOQL Group by IN Salesforce

String query = 'SELECT id,CreatedById,Product.Id,POCGrades__c ,fm_pocname__c,product.Name ,Visit.placeId, fm_poccode__c, createdby.LastName,Visit.LastModifiedDate, createddate, ActualBooleanValue'
+ ' FROM retailvisitkpi'
+ ' WHERE createddate = last_month and '
+ ' ( Product.Id = \'01t5j000003tszWAAQ\''
+ ' OR Product.Id = \'01t5j000003tszWAAQ\''
+ ' OR Product.Id = \'01t5j000003tt5nAAA\''
+ ' OR Product.Id = \'01t5j000003tsznAAA\''
+ ' OR Product.Id = \'01t5j000003tt1zAAA\''
+ ' OR Product.Id = \'01t5j000003tt7AAAQ\''
+ ' )';
I am having trouble to removes duplicate records based on Visit.placeID, can anybody help me out with soql
Just use hashmaps with the resulting query?
Map<String, retailvisitkpi__c> mapOfItems = new Map<String, retailvisitkpi__c>();
That will remove all the duplicates based on the Visit Place ID

Klarna checkout - using React & Node

I'm trying to implement Klarna checkout to accept payments.
When creating an order (first step of the checkout) you receive a "html_snippet" as response from Klarnas API (in my case to express backend). It requires that this snippet is shown in the front end (in my case react).
Having read Klarnas documentation, I still cant figure out how to show this html snippet in react. Even copy pasting the exact snippet gives me 41 error warnings.
The snippet looks like this:
html_snippet: '<div id="klarna-checkout-container" style="overflow: hidden;">\n' +
' <div id="klarna-unsupported-page">\n' +
' <style type="text/css">\n' +
' #-webkit-keyframes klarnaFadeIn{from{opacity:0}to{opacity:1}}#-moz-keyframes klarnaFadeIn{from{opacity:0}to{opacity:1}}#keyframes klarnaFadeIn{from{opacity:0}to{opacity:1}}#klarna-unsupported-page{opacity:0;opacity:1\\9;-webkit-animation:klarnaFadeIn ease-in 1;-moz-animation:klarnaFadeIn ease-in 1;animation:klarnaFadeIn ease-in 1;-webkit-animation-fill-mode:forwards;-moz-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-duration:.1s;-moz-animation-duration:.1s;animation-duration:.1s;-webkit-animation-delay:5s;-moz-animation-delay:5s;animation-delay:5s;text-align:center;padding-top:64px}#klarna-unsupported-page .heading{font-family: "Klarna Headline", Helvetica, Arial, sans-serif;color: rgb(23, 23, 23);font-size: 36px;letter-spacing: -0.2px;-webkit-font-smoothing: antialiased;}#klarna-unsupported-page .subheading{font-family: "Klarna Text", "Klarna Sans", Helvetica, Arial, sans-serif;color: rgb(23, 23, 23);-webkit-font-smoothing: antialiased;line-height: 28px;font-weight: 400;font-size: 19px;max-width: 640px;margin: 20px auto;}#klarna-unsupported-page .reload {cursor: pointer;outline: none;-webkit-tap-highlight-color: rgba(255, 255, 255, 0);border-width: 1px;background-color: rgb(38, 37, 37);border-color: rgb(38, 37, 37);padding: 15px 24px;margin-top: 15px;color: rgb(255, 255, 255);font-family: "Klarna Text", "Klarna Sans", Helvetica, Arial, sans-serif;font-weight: 500;text-rendering: geometricprecision;font-size: 100%;}\n' +
' </style>\n' +
' <h1 class="heading">Something went wrong</h1>\n' +
' <p class="subheading">Sorry for any inconvenience, please try reloading the checkout page or try again later.</p>\n' +
' <p class="subheading">If the problem persists it maybe be because you are using an old version of the web browser which is not safe nor compatible with modern web sites. For a smoother checkout experience, please install a newer browser.</p>\n' +
' <button class="reload" onclick="reloadCheckoutHandler && reloadCheckoutHandler()">Reload checkout</button>\n' +
' </div>\n' +
' <script id="klarna-checkout-context" type="text/javascript">\n' +
' /* <![CDATA[ */\n' +
' var reloadCheckoutHandler;\n' +
' (function(w,k,i,d,n,c,l){\n' +
' w[k]=w[k]||function(){(w[k].q=w[k].q||[]).push(arguments)};\n' +
' l=w[k].config={\n' +
' container:w.document.getElementById(i),\n' +
" ORDER_URL:'https://js.playground.klarna.com/eu/kco/checkout/orders/dae844ba-c44a-6e55-b5ad-9afe9055e1f4',\n" +
" AUTH_HEADER:'KlarnaCheckout 4mpla37op0i19pv6g054',\n" +
" LOCALE:'en-GB',\n" +
" ORDER_STATUS:'checkout_incomplete',\n" +
" MERCHANT_NAME:'Your business name',\n" +
' GUI_OPTIONS:[],\n' +
' ALLOW_SEPARATE_SHIPPING_ADDRESS:false,\n' +
" PURCHASE_COUNTRY:'gbr',\n" +
" PURCHASE_CURRENCY:'GBP',\n" +
' TESTDRIVE:true,\n' +
" BOOTSTRAP_SRC:'https://js.playground.klarna.com/kcoc/220119-c2c224d/checkout.bootstrap.js',\n" +
" FE_EVENTS_DISABLED:'false',\n" +
" DEVICE_RECOGNITION_URL:'https://js.playground.klarna.com/eu/kco/checkout/orders/dae844ba-c44a-6e55-b5ad-9afe9055e1f4/device_recognition',\n" +
' DEVICE_RECOGNITION_TYPE1:true,\n' +
" DEVICE_RECOGNITION_TYPE3_ORG_ID:'87rxrdob',\n" +
" DEVICE_RECOGNITION_TYPE3_REF:'KLRNA_87rxrdob_dae844ba-c44a-6e55-b5ad-9afe9055e1f4',\n" +
" CLIENT_EVENT_HOST:'https://eu.playground.klarnaevt.com'\n" +
' };\n' +
" n=d.createElement('script');\n" +
' c=d.getElementById(i);\n' +
' n.async=!0;\n' +
' n.src=l.BOOTSTRAP_SRC;\n' +
' c.appendChild(n);\n' +
' try{\n' +
" ((w.Image && (new w.Image))||(d.createElement && d.createElement('img'))||{}).src =\n" +
" l.CLIENT_EVENT_HOST + '/v1/checkout/snippet/load' +\n" +
" '?sid=' + l.ORDER_URL.split('/').slice(-1) +\n" +
" '&order_status=' + w.encodeURIComponent(l.ORDER_STATUS) +\n" +
" '&timestamp=' + (new Date).getTime();\n" +
' }catch(e){}\n' +
' reloadCheckoutHandler = function () {\n' +
' try{\n' +
" ((w.Image && (new w.Image))||(d.createElement && d.createElement('img'))||{}).src =\n" +
" l.CLIENT_EVENT_HOST+'/v1/checkout/snippet/reload?sid='+l.ORDER_URL.split('/').slice(-1)+\n" +
" '&order_status='+w.encodeURIComponent(l.ORDER_STATUS)+'&timestamp='+(new Date()).getTime();\n" +
' window.location.reload();\n' +
' }catch(e){}\n' +
' }\n' +
" })(this,'_klarnaCheckout','klarna-checkout-container',document);\n" +
' /* ]]> */\n' +
' </script>\n' +
' <noscript>\n' +
'Please enable JavaScript.\n' +
' </noscript>\n' +
'</div>'
Anyone been through this journey?
You may have already solved this, but I used Iframe to render the snippet. Make an HTML page with the received snippet inside and use that as the source for your Iframe.
<iframe
title='klarnaCheckout'
className='iframe'
srcDoc={klarnaHtml(klarna.html_snippet)}
frameBorder='0'
></iframe>
export const klarnaHtml = (snippet) => {
return `
<html>
<head> </head>
<body>
<textarea style="display: none" id="KCO">
${snippet}
</textarea
>
<div id="my-checkout-container"></div>
<!-- START - Dont edit -->
<script type="text/javascript">
var checkoutContainer = document.getElementById(
"my-checkout-container"
);
checkoutContainer.innerHTML = document
.getElementById("KCO")
.value.replace(/\\"/g, '"')
.replace(/\\n/g, "");
var scriptsTags = checkoutContainer.getElementsByTagName("script");
for (var i = 0; i < scriptsTags.length; i++) {
var parentNode = scriptsTags[i].parentNode;
var newScriptTag = document.createElement("script");
newScriptTag.type = "text/javascript";
newScriptTag.text = scriptsTags[i].text;
parentNode.removeChild(scriptsTags[i]);
parentNode.appendChild(newScriptTag);
}
</script>
<!-- END -->
</body>
</html>
`;
};

Build a dynamic string to filter a rest call

I'm trying to build a dynamic string but I'm facing a problem, so I kindly ask help to the community.
A have a string to build a rest call filter, but I'm lost with the and's
This query only works if only one filter condition is provided, but I have to provide as AND
var query;
var queryDefault = "IsLastForLevelAndParticipant eq 1";
this.state.participantFirstName
? query += "substringof('" + this.state.participantFirstName + "',Participant/FirstName)"
: queryDefault
this.state.participantLastName
? query += "substringof('" + this.state.participantLastName + "',Participant/LastName)"
: queryDefault
So let´s see.
If I start building this and only one filter is provided I'll have a plus and
var query;
var queryDefault = "IsLastForLevelAndParticipant eq 1";
this.state.participantFirstName
? query += "substringof('" + this.state.participantFirstName + "',Participant/FirstName) and "
: queryDefault
this.state.participantLastName
? query += "substringof('" + this.state.participantLastName + "',Participant/LastName)"
: queryDefault
query += " and " + queryDefault
I have 12 filters and I must know how many have values in order to provide the and clause
This is my state
//Filters Certificates
startEmission: string;
endEmission: string;
startValidity: string;
endValidity: string;
participantFirstName: string;
participantLastName: string;
paticipantCertNumber: string;
selectYesNo: string;
selectLevel: string;
Any help is a bonus.
Add all possible filters to an array, filter the falsy values and finally join all items with " and ".
var query = [
queryDefault,
this.state.participantFirstName && "substringof('" + this.state.participantFirstName + "',Participant/FirstName)"
this.state.participantLastName && "substringof('" + this.state.participantLastName + "',Participant/LastName)"
]
.filter(item => !!item)
.join(" and ");
BTW. are you using OData? the structure of the filter looks familiar. If you do, I would recommend you to use this library: https://github.com/techniq/odata-query#readme
Since I'm using datetime also, here it is the final solution
var queryDefault = "IsLastForLevelAndParticipant eq 1";
var query = [
queryDefault,
this.state.startEmission && "(Date1 ge datetime'" + moment.utc(this.state.startEmission).toISOString() + "') and (Date1 le datetime'"
+ moment.utc(this.state.endEmission).toISOString() + "')",
this.state.startValidity && "(Validto ge datetime'" + moment.utc(this.state.startValidity).toISOString() + "') and (Validto le datetime'"
+ moment.utc(this.state.endValidity).toISOString() + "')",
this.state.participantFirstName && "(substringof('" + this.state.participantFirstName + "',Participant/FirstName))",
this.state.participantLastName && "(substringof('" + this.state.participantLastName + "',Participant/LastName))",
this.state.selectYesNo && "IsPrinted eq " + this.state.selectYesNo,
this.state.selectLevel && "Level/Title eq '" + this.state.selectLevel + "'"
]
.filter(filter => !! filter)
.join(" and ");
var q = JSON.stringify(query).substring(1).slice(0, -1);
console.log(JSON.stringify(query));

How can I fix the URL fields in my Dynamic Lightning:Datatable so that the field labels display the name of each related record?

I am working on a lightning component that will display a custom, dynamic, list of 'related' records that can be used to display related records in a list on an object that is ALSO a child of the same parent. So, for example, If the Account is the parent record, and custom object 1 and custom object 2 are both children of the account, I want to display the custom object 1 records that are associated with the same account as custom object 2 on the custom object 2 lightning record page. I am using user inputs in the LC canvas and field sets to locate the records and display the columns, respectively.
The component I created works in that it does query and display the records, columns, and field values dynamically. I wanted to also include a clickable link to the custom object 1 records using the 'Name' field. However, I can't seem to dynamically set the typeAttribute of the Name field to display the label of the record. Because I am assigning it as an attribute of the column header, it is only taking the last value in the array.
Is there a way to assign the typeAttribute to the records response, and NOT the column header response?
Here is my code:
Apex Class:
public class DynamicRelatedListController {
#AuraEnabled
public static String fetchParent(String recId, String parentLookup, String objPageName) {
String strSOQL = 'SELECT Id, ' + parentLookup + ' FROM ' + objPageName + ' WHERE Id = \'' + recId + '\' LIMIT 1 ' ;
List <SObject> currentRecord = new List <SObject>(Database.query(strSOQL));
system.debug('Database Result for fetch parent ' + strSOQL);
List <String> parentIds = new List<String>();
for(SObject cr : currentRecord) {
parentIds.add(String.valueOf(cr.get(parentLookup)));
}
String parentId = parentIds[0];
return parentId;
}
#AuraEnabled
public static List < SObject > fetchChildren(String objectName, String criteria, String parentFieldAPIName, String recId, String parentLookup, String objPageName) {
String parentId = fetchParent(recId, parentLookup, objPageName);
// String prefix ='%' + GM_Util.findObjectNameFromRecordIdPrefix(parentId) + '%';
List < SObject > childRecordList = new List < SObject > ();
String strSOQL = 'SELECT Id, ' + parentFieldAPIName + ' FROM ' + objectName + ' WHERE ' + parentFieldAPIName + ' = \'' + parentId + '\'';
if ( String.isNotBlank( criteria ) )
strSOQL += ' ' + criteria;
childRecordList = Database.query(strSOQL);
system.debug('Database Result for fetch children ' + strSOQL);
return childRecordList;
}
#AuraEnabled
public static DataTableDetails fetchRelatedRecs(String recId, String fieldSetName, String criteria, String objectName, String parentFieldAPIName, String objPageName, String parentLookup)
{
DataTableDetails dataTableDtls = new DataTableDetails();
List<GM_Util_Aura.FieldSetMemberWrapperClass> listOfFieldSetMembers = new List<GM_Util_Aura.FieldSetMemberWrapperClass>();
if(fieldSetName != NULL && fieldSetName != ''){
listOfFieldSetMembers = GM_Util_Aura.getFieldSetMemberJSON(objectName, fieldSetName);
}
// List<GM_Util_Aura.FieldSetMemberWrapperClass> listOfFieldSetMembers = GM_Util_Aura.getFieldSetMemberJSON(objectName, fieldSetName);
List<String> WHERE_IN_LIST = new List <String>();
for (SObject crl: fetchChildren(objectName, criteria, parentFieldAPIName, recId, parentLookup, objPageName)) {
WHERE_IN_LIST.add(crl.Id);
}
String SQL = 'SELECT Id ';
if(listOfFieldSetMembers != null && listOfFieldSetMembers.size() > 0){
for(GM_Util_Aura.FieldSetMemberWrapperClass fsmwc : listOfFieldSetMembers){
dataTableDtls.fieldLabelsList.add(fsmwc);
SQL = SQL + ',' + fsmwc.fieldName;
}
}
SQL += ' FROM ' + objectName +' WHERE Id IN : WHERE_IN_LIST' ;
System.debug('final SQL statement (WHERE_IN_LIST): ' + SQL);
dataTableDtls.returnedParentRecords = Database.query(SQL);
System.debug('returned Parent Records are ' + Database.Query(SQL));
// filteredResults = Database.query(SQL);
System.debug('final filtered results are: ' + dataTableDtls);
System.debug('returned field labels are ' + listOfFieldSetMembers);
return dataTableDtls;
}
public class DataTableDetails{
#AuraEnabled
public List<sObject> returnedParentRecords = new List<sObject>();
#AuraEnabled
public List<GM_Util_Aura.FieldSetMemberWrapperClass> fieldLabelsList = new List<GM_Util_Aura.FieldSetMemberWrapperClass>();
}
}
My component helper & cmp code:
({
getDataTable: function(component, event) {
console.log("entered Get Data Table");
var action = component.get("c.fetchRelatedRecs");
action.setParams({
recId: component.get("v.recordId"),
objectName: component.get("v.ObjectAPIName"),
fieldSetName: component.get("v.FieldSetAPIName"),
objPageName: component.get("v.sObjectName"),
parentFieldAPIName: component.get("v.ParentFieldAPIName"),
parentLookup: component.get("v.ParentFieldLookupName"),
criteria: component.get("v.criteria")
});
action.setCallback(this, function(response){
//console.log("this is the fieldSetName " + fieldSetName)
var state = response.getState();
if(state === 'SUCCESS'){
var fieldSetResponse = response.getReturnValue().fieldLabelsList;
var parentRecordsResponse = response.getReturnValue().returnedParentRecords;
console.log("Parent records length " + parentRecordsResponse.length);
console.log("Field Set Length " + fieldSetResponse.length);
console.log("here are the field labels before data transformation " + JSON.stringify(fieldSetResponse));
console.log("Here are all the related records before transformation " + JSON.stringify(parentRecordsResponse));
//this for loop changes all lookup fields to type 'url' for clickable links
for(var i = 0; i < parentRecordsResponse.length; i++ ) {
if(fieldSetResponse[i].fieldName.includes('__r.Name')) {
fieldSetResponse[i].type ='url';
//drop the .Name from the lookup field so that the lightning:datatable can find the field value in the parentRecordsResponse object
fieldSetResponse[i].fieldName = fieldSetResponse[i].fieldName.replace('.Name', '') ;
//this for loop locates the key in the parentRecordsResponse object that matches the lookup field in the fieldSetResponse object.
for(var j = 0; j < parentRecordsResponse.length; j++) {
var arraykeys = Object.keys(parentRecordsResponse[j]);
var arrayvalues = Object.values(parentRecordsResponse[j]);
console.log("Array Keys in iteration "+ arraykeys[j]);
console.log("Array Values " + JSON.stringify(arrayvalues));
//this for loop locates the key in the parentRecordsResponse object that matches the lookup field in the fieldSetResponse object.
for(var h = 0; h <arraykeys.length; h++) {
console.log("Array Keys in iteration h "+ arraykeys[h]);
//fieldSetResponse[i]['typeAttributes'] = {label: arrayvalues[h].Name };
if(fieldSetResponse[i].fieldName === arraykeys[h]){
//assign the'type attributes' to the url field with the Name value of the lookup field
fieldSetResponse[i]['typeAttributes'] = {label: arrayvalues[h]['Name'] };
//transform the nested lookup field object to /recordId for the url
parentRecordsResponse[j][arraykeys[h]] = "/" + arrayvalues[h].Id ;
}
}
}
}
}
console.log("here are the field labels after data transformation " + JSON.stringify(fieldSetResponse));
console.log("Here are all the related records " + JSON.stringify(parentRecordsResponse));
//send the responses back to the controller and set them using the 'v.' keys
component.set("v.columnsHeader", fieldSetResponse);
component.set("v.listofRelatedRecords", parentRecordsResponse);
}
else if (state === 'ERROR'){
console.log('::::::::::::: ERROR :::::::::::::');
}
});
$A.enqueueAction(action);
}
})
<aura:component controller="DynamicRelatedListController" implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction,force:hasSObjectName" access="global">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:attribute name="ObjectAPIName" type="String"/>
<aura:attribute name="FieldSetAPIName" type="String"/>
<aura:attribute name="ParentFieldAPIName" type="String"/>
<aura:attribute name="ParentFieldLookupName" type="String"/>
<aura:attribute name="Criteria" type="String"/>
<aura:attribute name="TableName" type="String"/>
<!-- <aura:attribute name="recordId" type="String" /> -->
<aura:attribute name="columnsHeader" type="List"/>
<aura:attribute name="listofRelatedRecords" type="Object"/>
<lightning:card aura:id="lightCard" class="slds-card_boundary" title="{!v.TableName}" iconName="standard:file">
<div style="overflow-x: auto;">
<lightning:datatable data="{!v.listofRelatedRecords}"
columns="{!v.columnsHeader}"
keyField="Id"
hideCheckboxColumn="true"/>
</div>
</lightning:card>
</aura:component>
This is what the end result looks like - note that all of the values ARE different, except for the label of the Name field. The link itself works fine, and navigates to the appropriate record:
I figured it out. At a basic level, this line is missing the attribute of 'fieldName', which takes the API of the field name and applies the value.
So this: fieldSetResponse[i]['typeAttributes'] = {label: arrayvalues[h]['Name'] };
Should be this: fieldSetResponse[i]['typeAttributes'] = {label: fieldName: {API NAME OF FIELD THAT HOLDS THE DISPLAY VALUE} };
Even so, this is not possible to do dynamically because When the fieldName in this case is the lookup field itself, it displays the record Id. I could pass a hard-coded API name, but obviously that would defeat the purpose.
To get around this, I added a generic label (click to view record) and created a formula field on that target object that pulls in the parent record name and added that to my field set.
This is a known issue: https://trailblazer.salesforce.com/ideaView?id=0873A000000lLXYQA2
That could potentially be handled by creating a flattening function (although I haven't tried to implement that yet): https://developer.salesforce.com/forums/?id=9062I000000XtwnQAC

Ternary operation in check/in checking HTML checkbox

My JavaScript spits out dynamic HTML with one of the fields as checkbox based on a boolean as follows:
<input type="checkbox" disabled='true' (bool == true ? "Checked":"undefined") />
My checkbox always returns checked even if the Boolean is false .
Any suggestions to doing that by ternary operation?
Also i just realized that it would be hard to have id's for each row of checkboxes. Here is how my function currently looks like:
function fnBuildWebSiteClipHtml(name, url, id, allow_removal, use_full_screen) {
var html = "<tr id='wc_" + id + "'>" +
tdstart + "<div style='float: left; width: 20px'><img src='/emm/websiteIcon.do?id="+id+"' height='16px' width='16px'/></div><div style='float: left; vertical-align: middle;'>" + OrionCore.escapeHtml(name) + "</div></td>" +
tdstart + OrionCore.escapeHtml(url) + "</td>" +
tdstart + "<input type='checkbox' disabled='true' " + (allow_removal ? "checked='true'" : "") + "/>" + "</td>" +
tdstart + "<input type='checkbox' disabled='true' " + (use_full_screen ? "checked='true'" : "") + "/>" + "</td>" +
tdstart +
"<table>" +
"<tr>" +
"<td><a href='javascript:fnShowWebsiteclip(" + id + ")'>"+MESSAGES.edit+"</a> | </td>" +
"<td><a href='javascript:fnDeleteWebsiteclip(" + id + ")'>"+MESSAGES.del +"</a></td>" +
"</tr>" +
"</table>" +
"</td>" +
"</tr>";
return html;
}
Line 8 where i check the allow_removal and then following line with check for use_full_screen is what i am trying to have my checkboxes follow. Any suggestions towards that are much appreciated.
Thanks for an already posted response but i am not sure how to fit that here in this situation.
May be you need it?
<body onload="(bool ==true) ? document.getElementById('myTernaryCheckBox').setAttribute('checked', 'checked') : false">
<input type="checkbox" disabled id="myTernaryCheckBox"/>
</body>

Resources