none
how to display text dynamicaly using when field is empty RRS feed

  • Question

  • hi,

    have created view ,

    Requirrement:

    in view there is a column "Renewed " which could be emty, I want to show some text ( which is  "Register" ) here, when this field is empty else fine.

    Need to place if condition to show text, like we normally do it using if else condition to show text dynamically,

    How can I place this sort of condition to show text

    My view is

    Wednesday, January 22, 2020 2:01 PM

All replies

  • Hi,

    We can use JSLINK to achieve it, add the code below into script editor web part in this page to achieve it.

    <script type="text/javascript">
    (function () { 
        // Create object that have the context information about the field that we want to change it's output render  
        var fieldContext = {}; 
        fieldContext.Templates = {}; 
        fieldContext.Templates.Fields = { 
            // Apply the new rendering for Available field on List View 
            "Renewed": { "View": fieldTemplate } 
        }; 
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(fieldContext);
    })(); 
    
    // This function provides the rendering logic for list view 
    function fieldTemplate(ctx) { 
        var renewed = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];     
    	if(renewed==""){
    		 return "register";
    	}else{
    		 return renewed;
    	}   
    }
    </script>

    ReferenceSharePoint 2013 Working with Field Template using JSLink

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, January 23, 2020 1:51 AM
    Moderator
  • Which version of SharePoint are you using?

    Please remember to up-vote & mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, January 23, 2020 10:51 AM
  • 2016 on prem
    Friday, January 24, 2020 6:32 AM
  • what to apply here ?

            "Renewed": { "View": fieldTemplate }

    myview name is "RenewelDossierview" and item name/field name is "Renewed" on view.

    Friday, January 24, 2020 6:38 AM
  • fieldTemplate is the function (written below in the code) that returns the html which will be rendered for your field. So no change needed there.

    Please remember to up-vote & mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, January 24, 2020 7:05 AM
  • Hi,

    As HarshalGite's reply, the fieldTemplate is a function in the code.

    Did you meet some errors when using the code above?

    I suggest you read the article in my first reply to learn about the JSLINK.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.


    Friday, January 24, 2020 7:49 AM
    Moderator