Skip to main content
1-Visitor
Mar 17, 2017 1:26 AM UTC
Question

Document name auto assigned matching the document template picker

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?

7 replies

ShirishMorkhade
16-Pearl
Mar 22, 2017 3:05 PM UTC

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.

Translate
20-Turquoise
Mar 22, 2017 5:02 PM UTC

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);

    }

} 

Translate
ShirishMorkhade
16-Pearl
Mar 24, 2017 5:06 PM UTC

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

Translate
dchaves-21-VisitorAuthor
1-Visitor
May 31, 2017 2:29 PM UTC

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

Cheers,

Danilo

Translate