Toggle menu

Create an Article using the iCM API Worker

The example form related to this article uses the iCM API worker and iCM_obj_articleUpdate to turn a form submission into an article.

Many of the properties of iCM_obj_articleUpdate are optional, or assume sensible defaults.

Note that in this example the Default template (template ID 1) has a single field in the article extras, listed in the Extension property.

The example form also uses .utilCreateAction to create a custom confirmation message.

The Script Action

The main business of creating the article is carried out by a single script action.

function(helper, processor, props, context) {
    let result = helper.utilServerAPIServerCall("icmapi", "iCM_obj_articleUpdate", {
        "attributes": {
            "ArticleStruct": {
                "ArticleID": 0,
                "ArticleHeading": helper.queryFieldValue("HEADING"),
                "ArticleIntroText": helper.queryFieldValue("INTRO"),
                "ArticleText": helper.queryFieldValue("BODY"),
                "ArticleTemplateID": 1,
                "ArticleDisplay": "",
                "ArticleDate": "",
                "ArticleParentID": 2927,
                "ArticleDisplayDate": "",
                "ArticleDisplayEDate": "",
                "Archiveable": "",
                "ArchiveDate": "",
                "ArchiveParentID": "",
                "ArticleReviewDate": "",
                "ArticleReviewInterval": "",
                "Extension": {
                    "ENGLISHARTICLEID": ""
                }
            }
        }
    }, {
        "options": {
            "apiKey": "B9772652-XXXX-XXXX-XXXX-F9621EEB295E"
        },
        "rawMode": false
    });
    let msg = "";
    if (result.CONTENT && result.CONTENT.Status && result.CONTENT.Status == "Live") {
        msg = "Article created with ID: " + result.CONTENT.ArticleID;
    } else {
        msg = JSON.stringify(result);
    }

    helper.setVariable("ACTIONMSG", msg);

    return true;
}

Our API Key supplies the credentials of an iCM user with sufficient privileges to create articles beneath article ID 2927.

Last modified on 2 August 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon