[英]How to set a user's default view from JavaScript in Microsoft Dynamics
I'd like to set a users default view for a table depending on their business unit.我想根据他们的业务部门为表设置用户默认视图。
I found out you can set the default view like this:我发现您可以像这样设置默认视图:
async function setDefaultView(viewId: string) {
if(!viewId.startsWith('{') || !viewId.endsWith('}')) {
throw new Error('Your viewId should probably start and end with curly braces like this: {00000000-0000-0000-0000-000000000000}');
}
const userId = Xrm.Utility.getGlobalContext().userSettings.userId.slice(1, -1); // Remove the curly braces from the user id, because ODATA doesn't want them
await fetch(
`${window.location.origin}/api/data/v9.0/usersettingscollection(${userId})`,
{
method: "PATCH",
headers: { "Content-Type": "application/json; charset=utf-8" },
body: JSON.stringify({
personalizationsettings: `
<DefaultGridViews>
<DefaultGridView>
<EntityTypeCode>1024</EntityTypeCode>
<ChildEntityName></ChildEntityName>
<QueueId></QueueId>
<ViewId>${viewId}</ViewId>
<ViewType>1039</ViewType>
</DefaultGridView>
</DefaultGridViews>
`.replaceAll(/\s/g, '')
})
}
);
}
Note : This shouldn't overwrite the personalization settings for other tables.注意:这不应覆盖其他表的个性化设置。 When using patch, dynamics is smart enough to merge the personalizationsettings for you.使用补丁时,动力学足够智能,可以为您合并个性化设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.