Skip to main content
1-Visitor
March 17, 2017
Question

Document name auto assigned matching the document template picker

  • March 17, 2017
  • 2 replies
  • 3134 views

Is there a straightforward way to have the document name being dynamically generated to match the template name when a user creates a new document?

2 replies

16-Pearl
March 22, 2017

Hi Danilo Chaves

Yes, you can use JavaScript for that matter. I am not able to make it work with Name field, but I did it with IBA field. Refer below screen capture:

load.png

To do this, I have added below JavaScript function in "<WT_HOME>\codebase\netmarkets\jsp\document\create.jspf" file.

<script language="JavaScript">

  PTC.driverAttributes.on("afterRefresh",function() {

  setTimeout(function(){ getTemplateName(); }, 500);

});


// This function will retrieve Template value/name on Change Notice wizard

function getTemplateName() {

  // alert("test");

  var ele = document.getElementById('templatesCombo');

  var name = ele.options[ele.selectedIndex].text;

  // alert("Template name :: " + name);

  var chk = "-- Select a Template --";

  if (name == chk) {

  var elem = document.getElementById("model");

  elem.value = "";

  } else {

  var elem = document.getElementById("model");

  elem.value = name;

  }

}

</script>

I hope this helps you!

Regards,

Shirish

P.S. Please note, this is just for your reference. Please test and validate this on test environment first.

20-Turquoise
March 22, 2017

You can use jQuery to change the Name field. Using FireFox inspect element you can see there are actually 2 inputs whose id starts with "NameInputId". The difference is one is type text and the other is type hidden. The type text is the one you want to change so you could use jQuery like this:


function getTemplateName() { 

 

    // alert("test"); 

    var name = jQuery('#templatesCombo').val();

    // alert("Template name :: " + name); 

    var chk = "-- Select a Template --";

    if(name != chk) {

        //Note there are 2 inputs like this

        //The "real" one is type=text and there is also one of type=hidden

        //this will select the one of type=text and change it

        jQuery("input[id^=NameInputId][type=text]").val(name);

    }

16-Pearl
March 24, 2017

Hi Randy Jones,

I tried this Jquery example; however it is not populating Name field with Template Name. Instead it is populated with OID (VR:wt.doc.WTDocument:XXXXX).

docName.png

Thanks,

Shirish

dchaves-21-VisitorAuthor
1-Visitor
May 31, 2017

Thank you very much for the info guys! That worked perfectly for me.

Cheers,

Danilo