I am trying to call JavaScript function into my Custom Ribbon command. I was able to create my Custom Ribbon Action using this answer. This perfectly worked for me in creation of Custom Ribbon Action Button and JavaScript Alert also called successfully.
But my question is: Can we call JavaScript function from Custom Ribbon Action from some JS file uploaded in any library in Host Web of SharePoint App? (App may be SharePoint Hosted/Provider Hosted)
I have gone through this answer which says it's impossible to call JavaScript function but I am able to call JavaScript alert()
in Custom Action
When I tried following code in my App Installed
event, I got error like
The value specified for property Location for custom action {caa19918-a0b1-4cb9-8200-bafc2df31d43} is invalid. The value must be !ScriptLink.
clientContext.Load(clientContext.Web);
List list = clientContext.Web.Lists.GetByTitle("Details"); // or use GetByID or whatever
UserCustomActionCollection collUCA = list.UserCustomActions;
UserCustomAction Scriptaction1 = collUCA.Add();
Scriptaction1.Sequence = 2;
Scriptaction1.ScriptSrc = "~SiteCollection/SiteAssets/Assets/Scripts.js";
Scriptaction1.Title = title;
Scriptaction1.Location = "ScriptLink";
Scriptaction1.Update();
clientContext.ExecuteQuery();
When I remove ScriptLink
attribute and add any other attribute then I get error like
A validation error has occurred. The ScriptSrc property can only be used when the Location property has the value "ScriptLink".
So, I just wanted to know How can reference JavaScript to my Custom Ribbon Action from C# code?