Portal announcement

George_1
Giga Guru

I am creating records in the Announcement [announcement] table using a Record Producer.

I have added this Record Producer to multiple portals (e.g., Service Portal (SP) and HR Portal). When a user submits the Record Producer, the Announcement record gets created successfully.

However, I want to automatically associate the Announcement with the correct portal in the Portals related list (m2m_announcement_portal) based on where the Record Producer was submitted.

 

I am unable to reliably detect which portal the Record Producer was submitted from.

How can this be done?

 

George_1_0-1780414944273.png

 

3 REPLIES 3

Tanushree Maiti
Tera Patron

Hi @George_1 

 

Add the following script to the bottom of your existing Record Producer script

 

var spAnnounce = new GlideRecord('m2m_announcement_portal');
spAnnounce.initialize();
spAnnounce.announcement = current.sys_id;
spAnnounce.sp_portal = submittedPortalSysID; // Links to the portal
spAnnounce.insert();

 

Refer : Creating Portal Announcements Automatically from an Outage or Knowledge Article

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

George_1
Giga Guru

Hi @Tanushree Maiti thanks, 

 
but I have one Record Producer used in multiple portals , how do I dynamically set the portal instead of hardcoding

Hi @George_1 

 

Try this once:

Refer: https://www.servicenow.com/community/servicenow-ai-platform-forum/make-service-portal-banner-announc...

 

  1. Create a hidden Single line text variable  in your record producer
  2. Create a onLoad Catalog client script.

 

function onLoad() {

        try {

        var portal = spAnnouncement.getPortal(); // Native portal API

        if (portal) {

            g_form.setValue('current_portal', portal.sys_id);

        }

    } catch (e) {

        var portalURL = top.location.href;

        if (portalURL.indexOf('id=') > -1) {

            var portalName = g_form.getParameter('id');

            g_form.setValue('current_portal', portalName);

        }

    }

    g_form.setDisplay('current_portal', false);

}

 

 

  1. Update producer script:

 

var ann = new GlideRecord('announcement');

    ann.initialize();

    ann.name = 'Announcement created by ' + current.number;

    ann.title = producer.short_description;

    ann.summary = producer.description;    

    ann.from = new GlideDateTime();      

    ann.insert();

    var userPortal = producer.current_portal;

   

    if (userPortal) {

        var m2m = new GlideRecord('m2m_announcement_portal');

        m2m.initialize();

        m2m.announcement = ann.sys_id;

        m2m.sp_portal = userPortal;

        m2m.insert();

    }

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti