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.

14 REPLIES 14

Thanks for confirming.

Can you post the code that's calling the function?

I know it works in 6.9 SP2 so that's not the issue.

 Advisory Consultant

David,

The function call is working.  Validated by calling with another field name that happened to be a different type and it worked. 

Seems to not work for Date fields.  I tried adding another date field and put it on layout and neither one of the date fields is getting its FieldId returned when i pass their field names to the lookupFieldId function.

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

NeilGove1
Contributor III

Thanks David that works.

Thanks for confirming Neil.  Let me update my article with the latest code.

 Advisory Consultant