Add a link in a Broadcast message to open a record

149 views
Skip to first unread message

Nicolas Micoud

unread,
Dec 2, 2021, 5:25:42 AM12/2/21
to iDempiere
Hi,

I've managed to create a process that adds a broadcast message to some users in order they can have a look on some records.

ATM, is just a "raw" text ; is it possible to add a "link" that will open the record (defined via AD_Note.AD_Table_ID/Record_ID)?

Basically, it will be the same behaviour as right click / window on reports.

Or should I made some changes on the BroadcastMessageWindow and a button there ?

Thanks,

Nicolas

Heng Sin Low

unread,
Dec 2, 2021, 6:05:43 AM12/2/21
to idem...@googlegroups.com
add a button or it should be possible to modify the broadcastmessagewindow to looks for certain predefined format and render it as a link (like your smartphone able to recognize email and phone number in your message and render it as a clickable link).

--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/1c17e291-b540-499c-aba5-9d7b62aec0f0n%40googlegroups.com.

Nicolas Micoud

unread,
Dec 2, 2021, 6:14:23 AM12/2/21
to iDempiere
I think I can add the button.

But I like the predefined format option (but I'm not sure to have necessary skills).

It would looks like : "start of text #Link_TableID=132_Record_ID=456# end of text" ?

If so, how to generate the link to when use clicks on it, it adds a tab?

Heng Sin Low

unread,
Dec 2, 2021, 6:20:10 AM12/2/21
to idem...@googlegroups.com
the reaction for the link should be just a call to AEnv.zoom method to open as a normal window.

muri...@devcoffee.com.br

unread,
Dec 2, 2021, 6:47:54 AM12/2/21
to iDempiere
Hi @nicolas,

Inside a process, we create and publish the broadcast message for each record scheduled with:

MBroadcastMessage bdMessage = new MBroadcastMessage(getCtx(), 0, get_TrxName());
bdMessage.setBroadcastType(MBroadcastMessage.BROADCASTTYPE_ImmediatePlusLogin);
bdMessage.setBroadcastFrequency(MBroadcastMessage.BROADCASTFREQUENCY_UntilAcknowledge);
bdMessage.setTarget(MBroadcastMessage.TARGET_User);
bdMessage.setAD_User_ID(u.get_ID());
StringBuilder message = new StringBuilder();
message.append("Hi ").append(u.getName()).append(", <br>")
.append("You have an appointment at ")
.append(scheduledDate).append(" . <br>")
.append("Click here to see more information:<br>")
.append(getUrlZoom(po, uuid));

bdMessage.setBroadcastMessage(message.toString());
bdMessage.saveEx();
BroadcastMsgUtil.publishBroadcastMessage(bdMessage.get_ID(), get_TrxName());




And this is the method that creates the link to the window/record: 

private String getUrlZoom(PO po, String uuid) {

    StringBuilder url = new StringBuilder("");
    url.append("<a href=\"javascript:void(0)\" class=\"rp-href\" onclick=\"window.idempiere.zoomWindow(@#clientInfo_BroadcastComponentId@, '");
    url.append(po.get_KeyColumns()[0]);
    url.append("', '").append(po.get_ID()).append("','").append(uuid).append("')\">");
    url.append(po.get_ValueAsString(MCOBContrato.COLUMNNAME_DocumentNo)).append("</a>");

    return url.toString();
}

Nicolas Micoud

unread,
Dec 2, 2021, 7:54:16 AM12/2/21
to iDempiere
Hi,
thanks !

I've managed to show the link, it is "clikeable", but when clicking on it, nothing happens :-/

Not sure, but maybe the missing part is "@#clientInfo_BroadcastComponentId@", which is not references elsewhere ?


Nicolas

matheus....@devcoffee.com.br

unread,
Dec 2, 2021, 9:04:54 AM12/2/21
to iDempiere

Hi Nicolas !

At devCoffee, we implemented the event to handle this context in BroadCasMessageWindow, if you think this is useful, i can do a pull request or help you to do this. 


Matheus Marcelino

Nicolas Micoud

unread,
Dec 2, 2021, 9:30:22 AM12/2/21
to iDempiere
Hi Matheus,

I think is useful, so +1 if you can submit a PR :)

Thanks

Nicolas

matheus....@devcoffee.com.br

unread,
Dec 2, 2021, 10:00:12 AM12/2/21
to iDempiere
Nicolas the code below complements what murilo said: 

In MBroadCastMessage.java i've made this changes:

@Override
public String get_Translation (String columnName) {
    String translation = super.get_Translation(columnName );
    if(translation.indexOf('@') > 0)
    return Env.parseContext(getCtx(), 0, translation, false, false);

    return translation;
}

In BroadcastMessageWindow.java:

lines 121 to 124:

Env.setContext(Env.getCtx(), "#clientInfo_BroadcastComponentId", pnlHead.getUuid());
textMsgContent.setContent(mbMessages.get(0).get_Translation(MBroadcastMessage.COLUMNNAME_BroadcastMessage));
pnlHead.addEventListener(ZoomEvent.EVENT_NAME, this);
htmlDiv.setFocus(true);

lines 256 to 262:

} else if(event.getName().equals(ZoomEvent.EVENT_NAME)) {
    Clients.clearBusy();
    ZoomEvent ze = (ZoomEvent) event;
    if (ze.getData() != null && ze.getData() instanceof MQuery) {
            AEnv.zoom((MQuery) ze.getData());
    }
}

If @hengsin approves the idea,  i'll do a pr to be reviewed.

Matheus Marcelino

Nicolas Micoud

unread,
Dec 2, 2021, 10:53:10 AM12/2/21
to iDempiere
Is not working :(
I think issue relates to value of uuid of getUrlZoom.
What should it be ? uuid of the record or uuid of BroadcastMessageWindow ?
In his example, I don't see what is the source.

Thanks

Nicolas

matheus....@devcoffee.com.br

unread,
Dec 2, 2021, 11:20:30 AM12/2/21
to iDempiere
uuid of the ad_window to zoom. For Example, if po is instanceof MOrder, we need to use the sales order/purchase order window uuid ;)

Matheus Marcelino

Nicolas Micoud

unread,
Dec 2, 2021, 11:28:10 AM12/2/21
to iDempiere
ah yes ! works now !!
thanks

Haven't tested but I think it would be easier to passe the tableID and find the window (on BroadcastMessageWindow.onEvent) using Env.getZoomWindowID

Anyway, is perfect and is exactly what i was looking for

another +1 for trunk

Regards,

Nicolas

Martin Schönbeck

unread,
Dec 3, 2021, 8:35:53 AM12/3/21
to iDempiere
+1 here, too

Regards,
Martin

Nicolas Micoud

unread,
Jan 3, 2022, 6:33:10 AM1/3/22
to iDempiere
Hi hengsin,

is it ok for you to include that feature in trunk ?

Regards,

Nicolas

Heng Sin Low

unread,
Jan 3, 2022, 6:54:30 AM1/3/22
to idem...@googlegroups.com
Yeah, go ahead and create a PR for it.

Actually, there's no need to ask me or Carlos (unless you need input or there's something you are not sure of) before you create any PR and/or Jira tickets. The fact is, usually we can only start a more detailed discussion after you have created a Jira ticket and/or PR (for a better discussion, we need a detailed use case and/or actual code).

Nicolas Micoud

unread,
Jan 3, 2022, 7:45:14 AM1/3/22
to iDempiere
Reply all
Reply to author
Forward
0 new messages