Is it possible to store plumsail javascript functions in an external file

Hello,
instead of using the javascript menu in plumsail SP forms, is it possible to store functions like
fd.spRendered, fd.spBeforeSave in an external .JS file ? so that I don't need to update multiple forms if they all share the same JS functions.

Best regards
David

Dear @David74000,
Sure, that's actually a recommended approach when you want to be able to edit JavaScript for multiple forms, without having to open each one.

If you want to be able to access events, such as fd.spRendered() make sure that the script loads before that. That's why I recommend loading it via JS editor with one of the earlier events, like this:

fd.created(function(){
    var imported = document.createElement('script');
    imported.src = 'https://sharikov.sharepoint.com/sites/dev/Shared%20Documents/external.js';
    document.head.appendChild(imported);
})

Hi @Nikita_Kurguzov, thank you for your answer.
Unfortunately I have an error saying "fd is not defined" if I use the fd.spRendered function inside my external JS file :frowning: I used the fd.created event to include the file like you mentioned.
David

Dear @David74000,
Oh yeah, please, also add the following line to the JS editor:
window.fd = fd;

You can also do the same for other variables, such as $ or pnp to make them accessible.

Nice ! it works perfectly !

1 Like

Hi, Nikita_Kurguzov

Tell me please how can I call REST service with $.ajax from external file?
I tried to use window.$.ajax, but I got an error: "TypeError: Cannot read property 'ajax' of undefined"

For example I have such function:

function getCurrentUserGroups() {
	var userGroups = [];
	$.ajax({
		url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentuser/groups",
		method: "GET",
		headers: { "Accept": "application/json; odata=verbose" },
		async: false,
		success: function(data) {	
		    data.d.results.forEach(function (value) {
				userGroups.push(value.Title);
            });
		},  
        error: function(error) {  
            alert(error.responseText);
        },
	});
	return userGroups;
}

I found the solution.
It is need to add some lines to the code:

window.define = null;
window.fd = fd;
window.$ = $;