Is it possible to create SSJS functions as code resources in Web Studio and then use those functions in other CloudPages or Script Activities?
For example, if I created a function that generates an access token, I can definitely use it in the same CloudPage/script activity that it's created, but this might be useful in other places as well within the same Marketing Cloud account. I would ideally create this function as a code resource and then reference it in all activities that need it.
<script runat="server">
Platform.Load("Core","1");
function generateToken(clientId, clientSecret, authURL) {
var authUrl = authURL;
var contentType = 'application/json';
var authJSON = {
"clientId": clientId,
"clientSecret": clientSecret
}
var authPayload = Platform.Function.Stringify(authJSON);
var accessTokenResult = HTTP.Post(authUrl, contentType, authPayload);
var statusCode = accessTokenResult["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).accessToken;
return accessToken;
};
</script>
Thanks!