Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Using a client side JSON field in a serverside plugin.

$
0
0

Hello,

I'm trying to solve the following problem: I want to implement the new in-app notification functionality in one of our systems. Microsoft shows a large number of examples on how this can be solved on the client side using Javascript:

Send in-app notifications within model-driven apps (preview)

My implementation requires server-side execution using C#, which I haven't had much experience with yet. I was able to implement and successfully test the following logic:

void CreateNotification(PluginContext context, Guid userId, EntityReference EntityRef)
        {
            var referenceName = EntityRef.LogicalName;
            var referenceId = EntityRef.Id;

            var notification = new Entity("appnotification");
            notification["title"] = "New access.";
            notification["body"] = $"You have received new access rights to FirstLetterToUpper(referenceName)}";

            notification["icontype"] = new OptionSetValue(100000004);
            notification["toasttype"] = new OptionSetValue(200000000);
            notification["ttlinseconds"] = 120;

            // data (button with title and url
            var url = "?pagetype=entitylist&etn=" + referenceId + " & viewid=" + referenceId + "& viewType=1039";
            // I assume the JSON should be here?

            notification["ownerid"] = new EntityReference("systemuser", userId); 

            context.OrganizationService.Create(notification);
        }

My notification is shown to the correct system-user as expected.

I would now like to extend my code so that the user is also shown a button that leads him to the post. Microsoft published an example on how to do this using Javascript in their documentation: 

Notification with one action

A JSON String is used to show the title of the button and the url that should be opened when the button is clicked: 

"data": JSON.stringify({"actions": [
	  {"title": "View cases","data": {"url": "?pagetype=entitylist&etn=incident&viewid=00000000-0000-0000-00aa-000010001028&viewType=1039"
		}		
	  }
	 ]
	})

I haven't worked with JSON before. Is there a "replacement" for JSON in C#? I've seen examples using JSON.Stringify, but my attempts to implement it just threw errors.

So before I try my luck any further, I would like to ask for help as to whether such a functionality can be implemented at all with C# on the server side. Or whether it is necessary to write a script for such a notification and to trigger it on the server side.

I'm grateful for any advice!


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>