web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Accessing Web resource from Plugin code

(0) ShareShare
ReportReport
Posted on by

Hello all,

I have a JavaScript web resource added to Dynamics CRM 2016 on-premises, which refers to another XML web resource. Now I want to refer the JavaScript Web resource from my Plugin code or from Custom Workflow activity Code. Is this possible? if yes, how?

Thanks...

*This post is locked for comments

I have the same question (0)
  • Luke Sartain Profile Picture
    1,266 on at

    You can certainly access any web resources from within your code but you will not be able to execute your JavaScript - you can only run this client side.  If, for example, you have an XML web resource that you wish to read data from that's ok and you can use something like the below:

    public static XmlDocument retrieveXMLWebResource(IPluginExecutionContext context, IOrganizationService service, string webresourceName)
            {
                XmlDocument xmlDoc = new XmlDocument();
    
                ColumnSet cols = new ColumnSet();
                cols.AddColumn("content");
                QueryByAttribute requestWebResource = new QueryByAttribute
                {
                    EntityName = "webresource",
                    ColumnSet = cols
                };
                requestWebResource.Attributes.AddRange("name");
                requestWebResource.Values.AddRange(webresourceName);
    
                Entity webResourceEntity = null;
                EntityCollection webResourceEntityCollection = service.RetrieveMultiple(requestWebResource);
    
                if (webResourceEntityCollection.Entities.Count > 0)
                {
                    webResourceEntity = webResourceEntityCollection.Entities[0];
                    byte[] binary = Convert.FromBase64String(webResourceEntity.Attributes["content"].ToString());
                    string resourceContent = Encoding.UTF8.GetString(binary);
                    string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());                
                    if (resourceContent.StartsWith("\""))
                    {
                        resourceContent = resourceContent.Remove(0, byteOrderMarkUtf8.Length);
                    }               
    
                    xmlDoc.LoadXml(resourceContent);
    
                }
                return xmlDoc;
            }

    Hope that helps!

  • Suggested answer
    Alagunellaikumar Profile Picture
    6,212 on at

    Hi

    Accessing webresource through plugin or workflow is not possible.

  • meenxip Profile Picture
    on at

    Thank you Luke Sartin, is your code accessing XML web resource which is on CRM?

  • Verified answer
    Luke Sartain Profile Picture
    1,266 on at

    It is, yes.  You'll simply need to pass the name of the CRM webresource to that function and it will return it.  Just to reiterate, this will only work for XML web resources.

  • Suggested answer
    meenxip Profile Picture
    on at

    Thank you very much Luke, you gave me another idea to move the Javascript code to C# code to read XML web resource and I get a solution!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans