In one of our requirements, we wanted to create/send an email on the creation/update of the case with the description of the email same as the description of the case.
In our Case record, for the description, we have the line break (\n) specified.
However, for the email created, we see the line break ignored.
To fix this we might think of applying the below formula by replacing “\n” with “”.
This time we followed more or less the same steps, the main difference was this time we used our favorite XrmToolBox plugin SQL4CDS to perform the delete operations instead of the bulk deletion job.
However, even after deleting all the Activity type records (except one appointment record which was giving some error on deletion), as shown below, the ActivityPointer was still showing 13 GB of space occupied.
select activitytypecodename,activitytypecode, Count(activitytypecode) as Total
from activitypointer
group by activitytypecode, activitytypecodename
order by Total desc
And the same was true for the WorkflowLogBase, we used a bulk deletion job for deleting the system jobs with status as succeeded which deleted around 1200 records, however running the same query in SQL4CDS showed us around 70K records with status as success.
On trying to run the following query it gave us an “Expected non-empty Guid” error and we could not delete the records.
Eventually, we raised the Support Ticket for it, and the team ran the script in the background to delete/reduce the size of the Activity Pointer and Workflow Log table and eventually we were able to reduce the database usage (we also deleted few other table records)
Let us continue our previous post, here we will update the script to add an onchange event to the Identify Sales Team field in the Business Process Flow. Based on the value selected we will make the Develop Proposal field mandatory.
Below is the code we need to add for it.
function OnLoad(executionContext)
{
var formContext = executionContext.getFormContext();
formContext.data.process.addOnStageChange(CheckStageAndToggleFieldBPF);
CheckStageAndToggleFieldBPF(executionContext);
}
function CheckStageAndToggleFieldBPF(executionContext) {
var formContext = executionContext.getFormContext();
var activeStage = formContext.data.process.getActiveStage();
var activeStageId = activeStage.getId();
var stagePropose = "3a275c22-fc45-4e89-97fc-41e5ec578743";
if (activeStageId.toLowerCase() === stagePropose) {
formContext.getControl("header_process_identifypursuitteam").setDisabled(false);
}
else {
formContext.getControl("header_process_identifypursuitteam").setDisabled(true);
}
formContext.getControl("header_process_identifypursuitteam").getAttribute().addOnChange(function(executionContext) {
if (formContext.getControl("header_process_identifypursuitteam").getAttribute().getValue())
{
formContext.getControl("header_process_developproposal").getAttribute().setRequiredLevel("required");
}
else
{
formContext.getControl("header_process_developproposal").getAttribute().setRequiredLevel("none");
}
});
}
We can add it to the field if it is in the form also, that will also work the same. However, if we do not have the field on the form we need to add it to the field on the BPF.
On selecting the value completed for Identify Sales Team, we can see the Develop Proposal field being set as mandatory.
Later if we add the same field on the form, or into another stage of the BPF, the onchange event will apply and work for them.
Here to get the active stage ID, open the business process flow and get its Guid.
Then using the awesome SQL4CDS XrmToolBox plugin get the Guid of the particular stage.
function OnLoad(executionContext)
{
var formContext = executionContext.getFormContext();
formContext.data.process.addOnStageChange(CheckStageAndToggleFieldBPF);
CheckStageAndToggleFieldBPF(executionContext);
}
function CheckStageAndToggleFieldBPF(executionContext) {
var formContext = executionContext.getFormContext();
var activeStage = formContext.data.process.getActiveStage();
var activeStageId = activeStage.getId();
var stagePropose = "3a275c22-fc45-4e89-97fc-41e5ec578743";
if (activeStageId.toLowerCase() === stagePropose) {
formContext.getControl("header_process_identifypursuitteam").setDisabled(false);
}
else {
formContext.getControl("header_process_identifypursuitteam").setDisabled(true);
}
}
select processidname,stagename, processstageid from processstage
where processid = '919E14D1-6489-4852-ABD0-A63A6ECAAC5D'
Also if we have the same fields used in multiple places / stages in the Business Process Flow, we will have the suffix added to the fields, so we need to refer the field appropriately in our script.
Suppose we have the following whole number fields, where Field C is the calculated column and is the sum of Field A and Field B
Field C calculated column –
However, if any of the fields used for calculation is null, Field C will also show null.
The way we can resolve it is to put a null check in the formula.
We have created a new calculated column with the below definition.
The other option that we can consider is using JavaScript / Business Rules / Additional Calculated Columns to set the default value to 0 in case of null, for the fields being used for calculation.
In the case of 0 also, the calculated columns will work properly.
Finally, now that we have Fx Formula Columns available we can make use of them instead of Calculated Columns.
The formula columns work properly and we do not have to put the null check.
Select the appropriate environment and click on New copilot option (Create+)
Select Create
Here we have renamed the Copilot, next click on Add knowledge to add Dataverse as the source.
Add Dataverse
We can select up to 15 tables, and we have specified lead, contact, account, and case for now.
Next, we get the option to review the data for the tables selected.
In the last step, we get the option to review it. Here we can add/ edit the synonyms and glossaries that would make it easier for the copilot to understand and fetch the data. We’d skip it just to see how it works without configuring them.
Our copilot is ready now. The other things that we can do are to add actions, build topics, and publish which we’d leave as it is for now.
Click on the Knowledge tab. In a short time, we’d see the status changed to In Progress
Meanwhile, we can still go ahead and test it.
As we are done with the testing let us try publishing it, before that let us check the authentication for it.
Navigate to Settings >> Security >> Authentication, here we can see Authenticate with Microsoft selected. We’d leave it like that.
Based on the Authentication mode selected, we will have different channels enabled / disabled.
Let us select the Microsoft Teams channel for our copilot.
Select Turn on Teams
Select Edit details
Add / Edit the details and click on Save.
Now time to Publish our copilot.
We can now again open the Microsoft Teams channel and select the Availability options.
Here we can see multiple options, one is to share the link, upload the zip, and show it in the teams store.
We selected the Show to my teammates and shared users option. We can add search and add users to share it with them.
The other option is to Copy link and share the link.
On opening the link, we get the option to add the app.
We can see our app added in the Manage your apps section in Teams.
Finally now we can start interacting with our copilot.