It's all about the answers!

Ask a question

CreateArtifact API does not seem to work (callback never called)


sabio bucci (111) | asked Oct 03 '17, 11:09 a.m.

I'm trying to use the CreateArtifact API:
https://jazz.net/wiki/bin/view/Main/RMExtensionsAPI602#CreateArtifact
but it does not seem to work.

In particular the callback function is not called at all.

       var strategy = new RM.LocationSpecification(Mod_Ref, RM.Data.PlacementStrategy.BELOW);
       var attrs = new RM.AttributeValues();
        attrs[RM.Data.Attributes.ARTIFACT_TYPE] = 'Heading';
        RM.Data.Module.createArtifact(attrs, strategy, function(result) {

        window.alert("cccc");
        if (result.code === RM.OperationResult.OPERATION_OK) {
            //processNewArtifact(result.data);
            window.alert('aaa');
        } else {
            window.alert('aaab');
            //showWarning('Creation unsuccessful.');
        }
    });


In this example the window.alert("cccc") is never called.

What am I missing?
Thank you


Comments
1
Donald Nong commented Oct 03 '17, 7:52 p.m.

Have you subscribed the script to any events? Otherwise there is no way to call the script at all. Check the sample scripts for details.


1
Patrice AMBLARD commented Oct 27 '17, 12:47 a.m. | edited Oct 27 '17, 3:31 a.m.
 Hi,

Did you found the answer to your issue ?
I've got the same pb and the returned error is:
     Uncaught TypeError: Cannot read property 'Module' of null

I'm a little bit disapointed by the answer of Donald Nong: "Check the sample scripts for details" ! Of course we already check the sample and more than several times! My question is then the following "why all the examples provided in the RMExtensionsAPI602 are not done in such a way that we just have to copy/paste them to make them work ?". Here is an example of a copy/paste code I would expect to have for all services API. The code is for the getContentsStructure service and is located in file "my-own-gadget.js" for my-own-gadget OpenSocial gadget:

$(function() {
console.log("My own gadget");
});

// --------------------------------------
// Test for RM.Data.getContentsStructure
// --------------------------------------
RM.Event.subscribe(RM.Event.ARTIFACT_SELECTED, function(module) {
    console.log("--- Test for RM.Data.getContentsStructure ---");
RM.Data.getContentsStructure(module[0], [RM.Data.Attributes.PRIMARY_TEXT], function(result){
if(result.code == RM.OperationResult.OPERATION_OK) {
result.data.forEach(function(item){
console.log(item.values[RM.Data.Attributes.PRIMARY_TEXT])
});
}
else {
console.log("RM.OperationResult.OPERATION_KO");
return;
}
});
});

Among the provided examples, at least these ones are not working, due to few different reasons:
- RM.Data.getContentsStructure
- RM.Data.getValueRange
- RM.Data.Module.createArtifact
- etc...

Donald Nong commented Oct 27 '17, 3:39 a.m.

The reason I asked the OP to check the sample code is he had the impression that RM Extension API works as normal JavaScript, which is incorrect.

Your one probably falls in the same category. The API usually only works in the RM Web UI context. I don't know how you invoke it from an OpenSocial widget, but the "null" object may suggest that when the function is called, no RM artifact (the intended object) is actually "selected".

2 answers



permanent link
Patrice AMBLARD (61) | answered Oct 27 '17, 3:45 a.m.

 Hi,


I just found the answer, just add [0] to Mod_Ref :
 var strategy = new RM.LocationSpecification(Mod_Ref[0], RM.Data.PlacementStrategy.BELOW);
But I don't know why yet.
I found the solution working on the RM.Data.Module.removeArtifact example.

Actually, for RM.Data.getContentsStructure and getContentsAttributes this is the same pb, just add [0]:
- RM.Data.getContentsAttributes(module[0],
- RM.Data.getContentsStructure(module[0].

Spend to much time on that...

Regards.


Comments
Donald Nong commented Oct 27 '17, 3:52 a.m.

Is the same artifact (the module itself, or a module artifact within the module) selected in both cases?


permanent link
Patrice AMBLARD (61) | answered Oct 30 '17, 6:34 a.m.
Hi Donald,

For the getContentsStructure, I select a module in the "browse modules" page but without opening it. And it seems to me that I'm in the RM Web UI context because I added my openSocial Gadget through the project area window and my Gadget is on the left pane.
So what do I have to do to avoid adding the "[0]" ?

An other issue I found in the RM.Data.Module.moveArtifact code: is there a missing "});" instruction line for the structNodes.forEach(function(structNode) section ?

An other question; I'm trying to test the RM.Data.Module.moveArtifact code but when I select a Requirement artifact in a module I don't know (yet) how to retrieve the reference of the module containing this artifact to provide it to the flattenImmediateChildren function. Can you tell me how to do that ?

Regards.


Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.