528
edits
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"> | ||
async (args) => { | |||
console.log('args', args) | |||
const value = args[0]; | |||
const callout = args[1]; | |||
try{ | |||
await callout({ | |||
endp: 'getVersionData', | |||
contentVersionId: value | |||
}, | |||
false, | |||
'b3d.StandardFunctionsRouter').then(response => { | |||
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); | |||
} | |||
} | |||
</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]] |