Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

ModuleId or LevelId available when doing an AddNew content record?

NeilGove1
Contributor III

Is there a global variable or method that returns the moduleId or LevelId when doing an AddNew content record?

With the custom object that I am creating, I would like to write the code generically so I dont have to hard code a fieldId.  How can I get the fieldId generically when performing an AddNew?  I typically hard code the FieldAlias and look up the fieldId but this is not possible unless the code has the ModuleId or LevelId.

1 ACCEPTED SOLUTION

Accepted Solutions

See how this version works Neil.

     function lookupFieldId(fldName){
          var goFindId = null;

          try{
               $('.FieldLabel').each(function(){
                    if(($(this).text().indexOf(fldName + ':') != -1) && ($(this).text().indexOf(fldName + ':') == 0)){
                         goFindId = $(this).find("span")[0].id;
                         return false;
                    }
               });
          } catch (err) {console.log(err)}
          try {if (!goFindId) goFindId = $('.SectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}
          try {if (!goFindId) goFindId = $('.SubSectionLabel:findField("' + fldName + '")')[0].id;} catch (err) {}

          return goFindId ? $LM._layoutItems[goFindId.replace( /^\D+/g, '')].fieldId : 0;
     }

     $.expr[':'].findField = function(a, i, m) {
          return $(a).text().replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_').match("^" + m[3].replace(/[&\/\\#,+()$~%.'":*?<>{}]/g,'_') + "$");
     };

 Advisory Consultant

View solution in original post

14 REPLIES 14

DavidPetty
Archer Employee
Archer Employee

Neil, to get field ids you can use this custom object, The Horror's of Moving Custom Objects from One Environment to Another - RSA Link - 569029

 Advisory Consultant

JeffLetterman
Archer Employee
Archer Employee

When creating a new record, the URL parameters will include moduleId.  For example, the module id is 545 in the following: RSAarcher/GenericContent/Record.aspx?id=0&moduleId=545.  With that, you can make API calls to get names, fields, etc.

Hi David,

I couldn't get the lookupFieldId to work in 6.8 P4 HF2.

Thanks Jeff... I was able to parse window.location.search for the moduleId. 

Neil, is the field on layout?

Mine posting the code?

 Advisory Consultant

Jeff, 

It appears that I cannot get this work since the levelId is not available when doing an AddNew With fields with the same name on each level, then how do get the fieldId when I don't know the level?

Hi David,

I put the lookupFieldId function in the Sys.Application.add_load(function.

Also, tried with the lookupFieldId function outside of Sys.Application.add_load(function. but called it from within Sys.Application.add_load.

Are the fields on the layout and in the application the custom object is running in?

 Advisory Consultant

David,

The field that I want the FieldId for is on the layout of the application my custom object is running in.

The lookupFieldId function returns 0.