Hi, I am attempting to create a new session using the code below. When I press my button, it will open and create a new session. I would like to be able to add slugs for my agent scripts, but it does not appear to work.
private async createSession(params: string): Promise<IOutputs> {
try {
console.log("Params received in createSession:", params); // Log params
const json = JSON.parse(params);
const context = new Map();
context.set("parametersStr", json.parametersStr);
if ((window.parent as any).Microsoft.Apm) {
return await (window.parent as any).Microsoft.Apm.createSession({
templateName: json.templateName,
sessionContext: context,
isFocused: json.isFocused
}).then(
(_: any) => {
console.log("Session created successfully:", _);
return {
success: true,
message: '',
data: _
};
},
(_: any) => {
console.error("Error creating session:", _.message);
return {
success: false,
message: _.message,
data: ''
};
}
);
} else {
console.error("Microsoft.Apm not found in window.parent.");
return this._apmNotFound;
}
} catch (error) {
console.error("Error in createSession:", error);
return {
success: false,
data: undefined
};
}
}
Code I am attempting to add to create the custom slugs.
const fullName = Xrm.Utility.getGlobalContext().userSettings.userName;
const currentUserName = fullName.split(' ')[0]; // Extract first name
sessionContext.set("currentUserName", currentUserName);
Checking for it using Microsoft.Apm.getFocusedSession().getContext(); it is not available. The params show up in the console.log, but it is not accessible via the scripts.
Thanks for any suggestions!