Fetching id based on Name

nverma
nverma Member Posts: 396
I was wondering is it possible to fetch object id # , based on an object name.

Answers

  • nverma
    nverma Member Posts: 396
    SOLVED!
    IF ISCLEAR(PDFCreator) THEN
      CREATE(PDFCreator);
    IF ISCLEAR(PDFCreatorError) THEN
      CREATE(PDFCreatorError);
    
    IF CreatePDF.FIND('-') THEN BEGIN
    REPEAT
      ReportName := CreatePDF."Report Name";
     
      Object.SETFILTER(Object.Type, '%1', Object.Type::Report);
      Object.SETFILTER(Object.Name, ReportName);
      Object.FIND('-');
      ReportID := Object.ID;
    
      IF Object.GET(Object.Type::Report,'',ReportID) THEN;
      FileDirectory := 'J:\PLM\';
      FileName := ReportName +'.pdf';
     
      PDFCreatorError := PDFCreator.cError;
    
      IF PDFCreator.cStart('/NoProcessingAtStartup',TRUE) = FALSE THEN
           ERROR('Status: Error[' + FORMAT(PDFCreatorError.Number) + ']: ' + PDFCreatorError.Description);
    
      Window.OPEN('processing');
      WindowisOpen := TRUE;
      IF FileName = '' THEN
        ERROR('Please specify what the file should be saved as');
    
      Object.GET(Object.Type::Report,'',ReportID);
    
      PDFCreatorOption :=  PDFCreator.cOptions;
    
      PDFCreatorOption.UseAutosave := 1;
      PDFCreatorOption.UseAutosaveDirectory := 1;
      PDFCreatorOption.AutosaveDirectory := FileDirectory;
      PDFCreatorOption.AutosaveFormat := 0;                       //PDF file, you can also save in other formats
      PDFCreatorOption.AutosaveFilename := FileName;
    
      PDFCreator.cOptions := PDFCreatorOption;
      PDFCreator.cClearCache();
      DefaultPrinter := PDFCreator.cDefaultPrinter;
      PDFCreator.cDefaultPrinter := 'PDFCreator';
      PDFCreator.cPrinterStop := FALSE;
    
      REPORT.RUNMODAL(ReportID,FALSE,TRUE);
      Window.CLOSE;
      UNTIL CreatePDF.NEXT =0;
    END;
    
  • ppavuk
    ppavuk Member Posts: 334
    Just can't imagine a reason to do so :) Normally you know object id (like in printer selection).
  • nverma
    nverma Member Posts: 396
    the reason I had to do it this way is because I am creating a table, where the user will enter a name of the report that he wants a pdf copy off that report. Therefore, to use this line of code in PDFCreator, I had to first figure out what the ReportID (objectID) will be for that report.

    IF Object.GET(Object.Type::Report,'',ReportID) THEN;
    

    :)
  • ppavuk
    ppavuk Member Posts: 334
    If user will type in report name - this is bad design, users often do typo. :)

    If user will select report name from list form, based on object - you'll got id already :)
  • nverma
    nverma Member Posts: 396
    Your right.

    Therefore, I modified it so the user can see the list of reports that are available in the system and he can double click on the ones he want.