Hi @Anonymous
In case you must create a WebResource you would need 2 Steps:
1. Create record
Xrm.WebApi.createRecord("webresource", {content: window.btoa("<root/>"), displayname: "dummy", languagecode: 1031, name: "orb_dummy1.xml", webresourcetype: 4})
.then(console.log)
.catch(console.error)
//returns {id: "GUID", entityType: "webresource"}
2. Add Webresource to Solution
var req = {
ComponentId : {guid: "GUID"},
ComponentType: 61,
SolutionUniqueName: "YOURSOLUTIONNAME",
AddRequiredComponents: false,
IncludedComponentSettingsValues: null
};
req.getMetadata = function () {
return {
boundParameter: null,
operationName: "AddSolutionComponent",
operationType: 0,
parameterTypes: {
ComponentId: {"typeName": "Edm.Guid", structuralProperty: 1},
SolutionUniqueName: {"typeName": "Edm.String", structuralProperty: 1},
ComponentType: { structuralProperty: 1},
AddRequiredComponents: {structuralProperty:1}
}
};
};
Xrm.WebApi.online.execute(req).then(console.log).catch(console.error);
In case you have the WebResource and just need to update, you can use a normal update request. You need the id of the WebResource.
Xrm.WebApi.updateRecord("webresource", "GUID", {content: window.btoa("<XML_CONTENT/>")}).then(console.log).catch(console.error)
If you don't have the id of the webresource, you need to retrieve it first
Xrm.WebApi.retrieveMultipleRecords("webresource", `?$select=webresourceid&$filter=name eq '${encodeURIComponent("orb_dummy1.xml")}'`).then(console.log)
After the create or update is done, you need to publish:
var req = {
ParameterXml : "<importexportxml><webresources><webresource>${GUID}</webresource></webresources></importexportxml>"
};
req.getMetadata = function () {
return {
boundParameter: null,
operationName: "PublishXml",
operationType: 0,
parameterTypes: {
ParameterXml: {"typeName": "Edm.String", structuralProperty: 1}
}
};
};
Xrm.WebApi.online.execute(req).then(console.log).catch(console.error);
You can publish more resources at once.
Best regards,
Diana