# SyncClaimTypeMenus - Advanced Documentation ## Model Shape ``` SyncClaimTypeMenus(long ClaimTypeID, IEnumerable Menus) -> IEnumerable ``` MenuItemInfo (BaBackOffice.Model): ``` ID: long Text: string SortOrder: int ClaimHTML: string Widgets: WidgetInfo[] (required property, but SyncClaimTypeMenus ignores it entirely - widgets are synced separately via SyncMenuWidgets) ViewRoles: Role[] ``` ## Traps - This replaces the COMPLETE set of menus for the claim type. It queries the existing menus for ClaimTypeID, diffs their IDs against the IDs in the Menus you send, and hard-deletes any menu whose ID is not in your list. Sending a partial list deletes the rest. - Delete failure throws: "There was a problem deleting a menu[{id}]. {ge.LastError}" - This endpoint never touches Widgets, even though MenuItemInfo.Widgets is marked required on the model - whatever you put in Widgets here is ignored. Use SyncMenuWidgets to sync widgets within a menu. - A new menu (ID 0) must be created here before you can call SyncMenuWidgets against it - SyncMenuWidgets requires an existing Menu.ID. - Always fetch the current full menu list via GetClaimTypeByID first and send it back with only your intended changes applied - never construct a Menus list from scratch or you will delete every other menu on the claim type. ## Script Example ```javascript // Fetch-modify-save: never build a partial Menus list, or omitted menus get deleted var claimType = await CallEndpoint("SecureApi", "GetClaimTypeByID", { ClaimTypeID: claimTypeID }); var menus = claimType.Menus.map(m => ({ ID: m.ID, Text: m.Text, SortOrder: m.SortOrder, ClaimHTML: m.ClaimHTML, Widgets: m.Widgets, ViewRoles: m.ViewRoles })); menus.push({ ID: 0, Text: "New Menu", SortOrder: menus.length, ClaimHTML: "", Widgets: [], ViewRoles: [] }); var updated = await CallEndpoint("SecureApi", "SyncClaimTypeMenus", { ClaimTypeID: claimTypeID, Menus: menus }); ``` ## Cross-References | Endpoint | Relationship | |---|---| | GetClaimTypeByID | Fetch the current Menus[].Widgets[].Fields[] tree before syncing - always pass back the full set | | SyncMenuWidgets | Syncs widgets within one existing menu - call after the menu exists | | CopyMenuToClaimType | Calls SyncClaimTypeMenus and SyncMenuWidgets together to clone a menu onto a claim type | ---