I have two metadata drop-down columns added on a Shared Documents library upload form. I am leveraging SPServices to perform cascading and its working nicely. These drop-downs are: Project and Company Name.
Project Drop-down contains choices that are subsite names like Test Site 1, Test Site 2, Test Site 3. Now if a user is working on Shared Documents Library of Test Site 1 then on the library edit form, i would like to add code that reads the site name (Test Site 1) and finds that value from Choice drop-down and set it to Test Site 1 so that way users don't have to filter Project drop-down each time they perform an upload.
Can someone please help me with the JSOM code since I am working with SharePoint online, thanks in advance.
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script> <script type="text/JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { ExecuteOrDelayUntilScriptLoaded(retrieveWebSite, "sp.js"); }); function retrieveWebSite() { var clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl); this.oWebsite = clientContext.get_web(); clientContext.load(this.oWebsite); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); } function onQuerySucceeded(sender, args) { var sitename = this.oWebsite.get_title(); alert(sitename); $("select[title='Project Name']").val(sitename); sitename=null; } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } </script>