Custom Value Formatting: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
 
Line 38: Line 38:


=== Format Date Time to EU Format Date ===
=== Format Date Time to EU Format Date ===
This example is useful for formatting “CreatedDate” to a dd/mm/yyyy format. By default, salesforce returns a date-time value in the format YYYY-MM-DDTHH:MM:SS.ZZZ. This formatter will return the date-time in date only formatted to  dd/mm/yyyy:<syntaxhighlight lang="javascript" line="1">
This example is useful for formatting “CreatedDate” to a dd/mm/yyyy format. By default, salesforce returns a date-time value in the format YYYY-MM-DDTHH:MM:SS.ZZZ. This formatter will return the date-time in date only formatted to  dd/mm/yyyy:
 
Version < 1.16<syntaxhighlight lang="javascript" line="1">
value => new Date(value).toLocaleDateString(‘en-GB’);
value => new Date(value).toLocaleDateString(‘en-GB’);
</syntaxhighlight>Version > 1.16<syntaxhighlight lang="javascript" line="1">
//Option 1
(args) => args[0].toLocalDateString('en-GB')
//Option 2
(args) => {
    const value = args[0];
    const callout = args[1];
    return value..toLocalDateString('en-GB')
}
</syntaxhighlight>
</syntaxhighlight>


Line 64: Line 75:


=== API Callouts ===
=== API Callouts ===
You can use Value Formatters just like [[Custom Embedded JavaScript Functions|Function Expressions]] to connect to external systems<syntaxhighlight line="1">
You can use Value Formatters just like [[Custom Embedded JavaScript Functions|Function Expressions]] to connect to external systems (or APEX). In the example below, we are calling the apex class b3d.StandardFunctionsRouter and its method getVersionData, the response is parsed to return an embed element with the image. This has been applied to a ContentVersion.Id field as a value formatter.<syntaxhighlight line="1">
var getJSON = function(url, callback) {
async (args) => {
    var xhr = new XMLHttpRequest();
console.log('args', args)
    xhr.open('GET', url, true);
const value = args[0];
    xhr.responseType = 'json';
const callout = args[1];
    xhr.onload = function() {
      var status = xhr.status;
try{
      if (status === 200) {
await callout({
        callback(null, xhr.response);
endp: 'getVersionData',
      } else {
contentVersionId: value
        callback(status, xhr.response);
},
      }
false,
    };
'b3d.StandardFunctionsRouter').then(response => {
    xhr.send();
console.log('callout response from function expression: ', response);
};
let type = '';
if(response.responseObject.contentVersion.FileType == 'JPEG'){
type = 'image/jpeg';
}
return `
<embed type="${type}" src="${response.responseObject.data}"></embed>
`;
});
}catch(err){
console.error(err);
}
}


//Use like that
getJSON('http://query.yourdomain.com/v1/public/yql?q=test',
function(err, data) {
  if (err !== null) {
    alert('Something went wrong: ' + err);
  } else {
    return data.query.results
  }
});
</syntaxhighlight>
</syntaxhighlight>
[[File:FullCalendarJs.png|thumb|Full Calendar JS library]]
[[File:FullCalendarJs.png|thumb|Full Calendar JS library]]
[[Category:3B Docs Features]]
[[Category:3B Docs Features]]
[[Category:3B Docs]]
[[Category:3B Docs]]

Navigation menu