cancel
Showing results for 
Search instead for 
Did you mean: 

401 error in aikau while making Repo request

muralidharand
Star Contributor
Star Contributor

I was trying to help the below quention, with a simple example. could-anyone-provide-aikau-form-example-with-data-loading

Basically, I would do a repo request when the form dialog loads and wanted to display the document libray noderef in the dialog. So I called makeRepoRequest() during dialog load, but the network tab throws 401 error.

Please let me know, what is wrong with this sample?

/* studentForm.get.js */
function makeRepoRequest()
{
    var alfDestination = "something";


    var site = page.url.templateArgs.site;
    var result = remote.call("/slingshot/doclib/container/" + site + "/documentLibrary");
    return result.status.code;
    if (result.status.code == status.STATUS_OK) {
        alfDestination = JSON.parse(result).container.nodeRef;
    }
}

var formControls = [
  {
    name: "alfresco/forms/controls/TextBox",
    config: {
      name: "name1",
      label:"Name",
      placeHolder:"Enter Name Here",
      visibilityConfig: {
        initialValue: true
      }
    }
  },
  {
    name: "alfresco/forms/controls/TextBox",
    config: {
      label:"Age",
      name: "age",
      placeHolder:"Enter Age Here",
      visibilityConfig: {
        initialValue: true
      }
    }
  }
  ,
  {
    name: "alfresco/forms/controls/TextBox",
    config: {
      label:"NodeRef",
      name: "nodeRef",
      visibilityConfig: {
        initialValue: true
      },
      value : makeRepoRequest()
    }
  }
];

var showDialog = {
  name: "alfresco/buttons/AlfButton",

  config: {
    readOnly:"true",
    id:"dialog1",
    label: "Create New Student",
    additionalCssClasses: "call-to-action",
    publishTopic: "ALF_CREATE_FORM_DIALOG_REQUEST",
    publishPayloadType: "PROCESS",
    publishPayload: {
      dialogTitle: "Student Form",
      dialogConfirmationButtonTitle: "Register",
      dialogCancellationButtonTitle: "Cancel",
      formSubmissionTopic: "ALF_CRUD_CREATE",
      formSubmissionPayloadMixin: {
        url: "api/type/cm%3Astudent/formprocessor"
      },
      fixedWidth: true,
      widgets: formControls
    }
  }
};

model.jsonModel = {
widgets :[showDialog
         ],
services : [
            "alfresco/dialogs/AlfDialogService",
            "alfresco/services/CrudService"
        ]    
};‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
1 REPLY 1

kalpesh_c2
Star Collaborator
Star Collaborator

Hi,

You returned function without fetching data from the result.

function makeRepoRequest()
{
    var alfDestination = "something";
    var site = page.url.templateArgs.site;
    var result = remote.call("/slingshot/doclib/container/" + site + "/documentLibrary");
    if (result.status.code == status.STATUS_OK) {
        alfDestination = JSON.parse(result).container.nodeRef;
    }
    return alfDestination;
}‍‍‍‍‍‍‍‍‍‍


As described in above code your function should return alfDestination after fetching a data from the JSON.

Thanks,

Kalpesh

ContCentric