How to tell if iFrame is in Account or Opportunity Page?
export const quotesDetailSubmitPre = async ({ api }) => { const { crmManager } = api; const isAccountPage = await crmManager.isAccountPage(); const isOpportunityPage = await crmManager.isOpportunityPage(); if(isAccountPage) { // Your code } if(isOpportunityPage) { // Your code } };
Used API’s: isAccountPage, isOpportunityPage
Get Data from CRM
To get data from a CRM, Pricefx should be placed into CRM system. Currently, Pricefx doesn’t have any possibility to access CRM system data outside the CRM (except PlatformManager).
Use getPayload
export const quotesDetailSubmitPre = async ({ api: { crmManager } }) => { const payload = await crmManager.getPayload(); console.log(payload); };
Returns data from the current CRM page. For example: if getPayload is triggered under account page in Salesforce, getPayload will return all data from that specific account: accountId, accountName and etc.
Used API’s: getPayload
Use Data from getPayload
export const quotesDetailSubmitPre = async ({ api: { crmManager } }) => { const payload = await crmManager.getPayload(); // To find what values exist in payload // Can be removed later when not needed console.log(payload); // If name in payload can be not existing await quoteAPI.setHeaderValue('label', payload.name || 'Name do not exist in payload'); };
Used API’s: getPayload, setHeaderValue
Change Inputs/outputs in pricefx CLIC Modules
To populate value/result for inputs in Pricefx with interceptor is fairly easy to do. You can change both inputs and outputs values in Pricefx modules.
To do so, you will need to:
Choose interceptor method which has scope
detail
.Add to parameters CLIC API, for example:
quoteAPI
,compensationPlanAPI
or …Inside module write
await quoteAPI.setHeaderValue('label', 'pricefx Pivo a Párek');
. This function will set value in header, but there are also functions for setting header input value, output result and line items inputs.
Full code example for inptus:
export const quotesDetailOpen = async ({ quoteAPI }) => { await quoteAPI.setHeaderValue('label', 'pricefx Pivo a Párek'); }
export const quotesDetailOpen = async ({ quoteAPI }) => { // Simple inputs await quoteAPI.setHeaderInputValue('ProjectID', 'Some ID'); await quoteAPI.setHeaderInputValue('ProjectName', 'Project Name'); }
export const quotesDetailOpen = async ({ quoteAPI }) => { // Input with configurator await quoteAPI.setHeaderInputValue('Configurator_Documents', { InvoiceMethod: 'Invoice method', OpportunityOwner: 'Name', OpportunityOwnerEmail: 'Email', OpportunityOwnerPhone: 'Phone', OpportunityOwnerTitle: 'Title' }); }
Full code example for outputs:
export const quotesDetailOpen = async ({ quoteAPI }) => { await quoteAPI.setHeaderOutputResult('outputName', 'pricefx Pivo a Párek'); }
Used API’s: setHeaderInputValue, setHeaderValue, setHeaderOutputResult
Edit Dashboard inputs
Initially, you will not know what inputs dashboard has, so on first run try to console.log dashboard and check what is inside
export const dashboardsInputsSet = async ({ api, dashboard }) => { console.log(dashboard) return; }
Save value from the dashboard somewhere as it can be handy in the future
Now let’s fill dashboard inputs with values from CRM
export const dashboardsInputsSet = async ({ dashboard, api }) => { // here we are destructuring api // so we wouldn't need to write api in front of methods that we often use // for example: crmManager and notify const { notify, crmManager } = api; // This method return true of false depending on where pricefx currently is running const isAccount = await crmManager.isAccountPage(); // in condition we are checking if dashboard // is with a name of the dashboard which we want to update if (isAccount && dashboard?.uniqueName === 'Dashboard_SoupPricing') { // here we are getting values from CRM const payload = await crmManager.getPayload(); // dashboard is mutable variable, we can modify inputs inside of this variable dashboard.inputs[0].value = { "Customer": payload.AccountNumber }; // We can check if dashboard variable updated as we want console.log("Updated dashboard input:", dashboard.inputs[0]); } if (isAccount && dashboard?.uniqueName === 'Dashboard_PivoPricing') { const payload = await crmManager.getPayload(); dashboard.inputs[0].value = { "Customer": payload.AccountNumber, "PivoType": 'Lager' }; console.log("Updated dashboard input:", dashboard.inputs[0]); } // this is what we are returning to the dashboard return { run: 'yes', dashboard }; };
Used API’s: isAccountPage, getPayload
Get Data from Other Object Using FindByQuery
In these examples, we will show how to get data from the Account (but you can get data and from any other object) while iFrame is placed on Opportunity page.
export const quotesDetailOpen = async ({ api, quoteAPI }) => { const { crmManager } = api; const isOpportunityPage = await crmManager.isOpportunityPage(); // First let's check if interceptor is running under opportunity page if(isOpportunityPage) { // Now we need data from Opportunity page const payload = await crmManager.getPayload(); // Now using payload and string formating // create query which we will run in Salesforce. // In this query we are geting all fields from account where id is equel to id // from what we have under this opportunity page and also // we added limit 1 so it wouldn't search for other account as only one account // should exist with this id. const query = ` SELECT * FROM Account WHERE Id = ${payload.AccountId} LIMIT 1 `; // now lets execute this query const accounts = await crmManager.findByQuery(query); // using console.log you can find what is inside console.log(accounts) // we need to test is we found any account if(accounts.length > 0) { const account = accounts[0]; // now lets set input value in pricefx using data from account await quoteAPI.setHeaderInputValue('AccountNumber', account.AccountNumber); } else { console.error('account not found!') } } return; }
Used API’s: findByQuery, isOpportunityPage, getPayload, setHeaderInputValue