Mirror API: Not receiving notifications when user selects custom menu item - google-mirror-api

I'm using the .NET Google Mirror API library for all of this.
I start by inserting a new timeline item which includes the built-in Delete menu item plus a custom menu item:
TimelineItem item = new TimelineItem() {
Text = "Test Item",
Notification = new NotificationConfig() { Level = "DEFAULT" },
MenuItems = new List<MenuItem>() {
new MenuItem() { Action = "DELETE" },
new MenuItem() {
Action = "CUSTOM",
Id = "report",
Values = new List<MenuValue>() { DisplayName = "Report" }
}
}
}
I'm also subscribed to timeline notifications, with no Operation specified (so it should receive all operations). When I select the 'Report' menu item on my Glass, my subscription does not receive a notification. When I select the 'Delete' menu item on my Glass, my subscription gets a notification for the DELETE, which also includes both the Delete and the Report actions in the UserActions field.
Is there something special I need to do to receive notifications for the custom menu item?

If you are getting built-in menu events such as DELETE, but you are not getting Custom menu events, then your only problem should be handling custom events, not getting them.
To test it;
Be sure that you are adding custom menu item to your timelineItem(as
you shared your code, I see that you are adding it)
Subscribe to timeline updates(you wrote that you've subscribed and got DELETE menu event)
Add Payload attribute to your custom menu item.
At your notifyCallback servlet, handle that Payload value.
This is a JAVA code for handling built-in and custom notifications, I guess you can write similar code with .NET. Logic is same:
Adding custom menu item:
List<MenuValue> menuValues = new ArrayList<MenuValue>();
menuValues.add(new MenuValue().setDisplayName("Test it!"));
menuItemList.add(new MenuItem().setValues(menuValues).setId("MY_CUSTOM_MENU_ITEM_ID").setAction("CUSTOM").setPayload("MY_CUSTOM_MENU_ITEM"));
timelineItem.setMenuItems(menuItemList);
Handling custom menu item:
// notificationString comes from inputStream of Mirror API's notify request.
Notification notification = jsonFactory.fromString(notificationString, Notification.class);
if (notification.getUserActions().contains(new UserAction().setType("DELETE"))) {
LOG.info("It was a DELETE of a timeline card.");
} else if (notification.getUserActions().contains(new UserAction().setType("CUSTOM").setPayload("MY_CUSTOM_MENU_ITEM"))) {
LOG.info("It was a MY_CUSTOM_MENU_ITEM of a timeline card.");
}

Related

How to get Parent id on Related list in salesforce

How to get parent id on custom button click of the related list.
Question Exploration:- when we open the Account detail record page and go in the related tab we have a contact list there and a new button on the contact list tile...when we click that new button new record modal is open with a pre-populated account in it.
so, I have to create a custom button that does this same thing.
When you click your custom button, the context is passed in the URL as a variable named inContextOfRef and the value is a base64-encoded string. You can get this value from the URL and decode it in your component. For LWC, you could do something like this:
import { LightningElement } from 'lwc';
export default class MyCoolLWC extends LightningElement {
// this variable will contain the parent record Id
recordId;
// this executes when your LWC is loaded
connectedCallback() {
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop)
});
let inContextOfRef = params.inContextOfRef;
if (inContextOfRef.startsWith("1\.")) { inContextOfRef = inContextOfRef.substring(2); }
var addressableContext = JSON.parse(window.atob(inContextOfRef));
this.recordId = addressableContext.attributes.recordId;
}
}

Call lightning Web Component from URL and capture parameter from URL

I want to redirect user from one LWC to another by clicking on URL in experience cloud. Basically, on my first LWC I am showing the list of records retrieved from Apex and then when any row is clicked, I want to pass recordId of that row and redirect to second LWC which will show the record details page. How can I achieve this?
Do you have a Community... sorry, Experience Builder page with that target LWC dropped?
You could use NavigationMixin although documentation says communities don't support the state property.
On source side try something like
/* Assumes the link/button clicked looks like
<button data-id={acc.Id} onclick={handleClick}>Get details</button>
*/
handleClick(event){
if(event.currentTarget.dataset.id){
this[NavigationMixin.Navigate]({
type: 'comm__namedPage',
attributes: {
name: 'MyTargetCommunityPage__c'
},
state: {
id: event.currentTarget.dataset.id
}
});
}
}
And then on target page's LWC it should be accessible as
connectedCallback() {
if(window.location.href){
try{
let url = new URL(window.location.href);
var id = url.searchParams.get('id');
if(id){
this.myId = id;
}
} catch(e){
if(console){
console.log(JSON.stringify(e));
}
}
}
}
If Navigation gives you hard time you can ditch it and go straight for window.open('/pagename?id=123', _self); or something. It's bit annoying that you have 1 set of rules for core Salesforce, 1 for community.
(if you have a namespace - you might need to use myns__id in the state instead of id)

Handle the actions after clicking Save button for standard new/edit record modal

I have a custom lwc component, with a new button. I am using NavigationMixin to leverage the standard new record creation form on pressing the New button on the custom component. Is there a way where I can control the actions to be performed after I click save on the standard form.
Here is sample code used to navigate to the New record creation form. I want to control the actions to be performed after I click save.
this[NavigationMixin.Navigate]({
type: 'standard__objectPage',
attributes: {
objectApiName: this.items.relatedObjectApiName,
actionName: "new"
},
state: {
nooverride: '1',
defaultFieldValues: this.items.relatedFieldApiName+"="+this.recordId,
recordTypeId: recTypeId
}
});

backbone model getting created multiple times with rapid clicks

When the user clicks this camera icon the get a snapshot of the page in a modal. If they click repeatedly it will make multiple snapshots before the modal has loaded and essentially blocked the camera icon.
Is there a way that I can say if a snapshot modal has just been created do not create another one?
events: {
'click .snapshot-camera' : 'clickCamera'
}
clickCamera: (event) ->
event.preventDefault()
#snapshot = new ******.Models.Snapshot({ user_id: ******.State.get('signInUser').id })
You can use underscore's debounce method which prevents double submissions.
// prevent double-click
$('button.my-button').on('click', _.debounce(function() {
console.log('clicked');
/* .. code to handle form submition .. */
}, 500, true);
Have a look into the below article
http://jules.boussekeyt.org/2012/backbonejs-tips-tricks.html

getting record from rowEdit in mvc extjs

I'm using the rowEditing on my grid in my mvc application. I'm able to handle the event when the user clicks update. However i'm having issues get the selected record. The below behaves strangely. I do not get the record.data.Name value the first time i click update. Tho i can see the value in fire bug.
init: function () {
this.control({
'button[text=Update]': {
click: this.onMaterialUpdate
}
});
},
onLaunch: function () {
},
onMaterialUpdate: function (button) {
var grid = Ext.getCmp('materialsContainer');
var record= grid.getSelectionModel().getSelection()[0];
if (record != null) {
console.log(record.data.Name);
}
}
Not sure about it... but I think the click event happens before completeEdit, thus the record is neither committed, nor updated in the grid (or its selection).
Perhaps try to capture the edit event of the row editor instead of click? You should get the correct record there?
I'd suggested handle edit event of the RowEditor plugin. You could subscribe to this event on grid render event for example. By getting the plugin by pluginId.

Resources